我需要访问 App.js 中的 redux 状态。
我目前正在使用导航组件“开关”来处理我的应用程序路由,并且我正在使用connect
and mapStateToProps
,它允许我在mapStateToProps
函数中查看我的应用程序状态。这个问题是 App.js 中的 this.props 不会返回任何状态。
我正在尝试通过我的 redux 状态将 isAuthenticated 传递给 Switch。
应用程序.js:
function mapStateToProps(state) {
console.log(state.token)
return{
token: state.token
}
}
let Container = connect(mapStateToProps, null)(Switch(this.props.token.isAuthenticated))
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
signedIn: false,
checkedSignIn: false,
};
}
render () {
console.log('props')
console.log(this.props)
const { checkedSignIn, signedIn } = this.state;
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Container />
</PersistGate>
</Provider>
)
}
}