React Navigation + Redux:如何将道具传递给StackNavigator?

时间:2017-07-06 13:21:48

标签: react-native react-navigation

我尝试使用redux设置StackNavigator。

import { connect } from "react-redux";
import { StackNavigator } from "react-navigation";

import ChatList from "../chat/chat-list";
import ChatDetail from "../chat/chat-detail";

// how do we pass props into this??
const ChatContainer = StackNavigator({
  ChatList: {
    screen: ChatList
  },
  ChatDetail: {
    screen: ChatDetail,
    navigationOptions: ({ navigation }) => ({
      title: "Jesus",
      tabBarVisible: false
    })
  }
});

export default connect(state => ({
  cool: state.cool,
}), dispatch => ({}))(ChatContainer);

我如何将cool传递给StackNavigator并传递给ChatList?

1 个答案:

答案 0 :(得分:3)

您可以使用Navigator Props

const SomeStack = StackNavigator({
  // config
});

<SomeStack
  screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}
/>

https://reactnavigation.org/docs/navigators/stack#Navigator-Props

react-navigation 3.x的新链接

https://reactnavigation.org/docs/en/stack-navigator.html#navigator-props