我尝试使用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?
答案 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