Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native with Redux : state changes not showing in console

When I put console.log('test') statements in my reducer, I can see them in the console when the actions are called. But I'm not seeing the redux "NEXT STATE"/ "PREV STATE" stuff in the console.

Is there anything basic I could be missing?

In the code below - I'm not trying to make any real functionality happen, I'm just trying to setup redux and see the state change in the console (so I know I'm on the correct path).


Container

import React, { PropTypes } from 'react-native';
import Header from './Header';
import { connect } from 'react-redux';
import { leave } from './actions';
import { join } from './actions';

const mapStateToProps = (state) => {
  return {
    in: state.in
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    join: (id) => {
      dispatch(join(id))
    },
    leave: (id) => {
      dispatch(leave(id))
    }
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(Header);

Reducer

export default function Header(state = { in: false }, action = {}) {
  switch (action.type) {
    case 'LEAVE':
      return {
        ...state,
        in: false
      }
    case 'JOIN':
      console.log(state);
      console.log(action);
      console.log('join');
      return {
        ...state,
        in: true
      }
    default:
      return state;
  }
}

Actions

export const join = (id) => {
  return {
    type: 'JOIN',
    payload: {
      in: true
    }
  }
}

export const leave = (id) => {
  return {
    type: 'LEAVE',
    payload: {
      in: false
    }
  }
}
like image 295
Elliot Avatar asked Mar 02 '26 20:03

Elliot


1 Answers

It solved when I realized that https://github.com/fcomb/redux-logger is needed to be installed separately.

like image 173
Elliot Avatar answered Mar 05 '26 09:03

Elliot