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

React Navigation + Redux: How to pass props into StackNavigator?

我正在尝试使用 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?

您可以使用 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

反应导航新 link 3.x

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