Q:

react-native / redux - action not working?

I'm playing with react-native / redux and am dispatching an action that is supposed to display a number yet an error gets thrown:

Unhandled JS Exception: Objects are not valid as a React child (found:
  object with keys {type, payload}). If you meant to render a collection
  of children, use an array instead or wrap the object using
  createFragment(object) from the React add-ons. Check the render method
  of Text.

createStore.js
import { createStore, applyMiddleware, combineReducers } from 'redux';
import createLogger from 'redux-logger';
import numReducer from './reducers/numReducer';

const logger = createLogger();

export default (initialState = {}) => (
  createStore(
    combineReducers({
      numbers: numReducer
    }),
    initialState,
    applyMiddleware(logger)
  )
);

App.js
import React from 'react';
import { Provider } from 'react-redux';
import HomeScreen from './components/HomeScreen';
import createStore from './createStore';

const store = createStore();

export default () => (
  <Provider store={store}>
    <HomeScreen />
  </Provider>
);

numReducer.js
import { LIST_NUMBERS, PICK_NUMBER } from '../actions/actionTypes';

export default (state = [], action = {}) => {
  switch (action.type) {
    case LIST_NUMBERS:
      return action.payload || [];
    case PICK_NUMBER:
      return action.payload;
    default:
      return state;
  }
};

HomeScreen.js
import React from 'react';
import { View } from 'react-native';
import NavContainer from '../containers/NavContainer';

const HomeScreen = () => (
  <View>
    <NavContainer />
  </View>
);

export default HomeScreen;

NavContainer.js
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

import { listNumbers, pickNumber } from '../actions/numberActions';

import Nav from '../components/Nav';

const mapStateToProps = state => ({
  numbers: state.numbers
});

const mapDispatchToProps = dispatch => (
  bindActionCreators({
    listNumbers,
    pickNumber
  }, dispatch)
);

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

Nav.js
import React, { Component, PropTypes } from 'react';
import { View, Text } from 'react-native';

export default class Nav extends Component {

  render() {
    return (
      <View>
        <Text>FirstLine</Text>
        <Text>SecondLind</Text>
        <Text>Number: {this.props.pickNumber(3)}</Text>
      </View>
    );
  }

}

Please advise what I am doing wrong. Thank you

A:

You need to dispatch your action from inside one of your lifecycle methods or on some handler, and then use the (updated) props from your redux store in your component.
Example: 
import React, { Component, PropTypes } from 'react';
import { View, Text } from 'react-native';

export default class Nav extends Component {
  componentDidMount() {
    this.props.pickNumber(3);
  }
  render() {
    return (
      <View>
        <Text>FirstLine</Text>
        <Text>SecondLind</Text>
        <Text>Number: {this.props.numbers}</Text>
      </View>
    );
  }

}

