gpt4 book ai didi

javascript - 是否可以在与 相同的渲染函数中访问 redux 存储状态

转载 作者:行者123 更新时间:2023-12-01 01:21:16 25 4
gpt4 key购买 nike

所以我的意思是:

const App = () => {
return (
<Provider store={store}>
<h1>{store.state.title}</h1> // For example
</Provider>
);
}

因此,在上面的示例中,我尝试访问状态中的 title 属性。

最佳答案

是的,您可以使用store.getState()

所以在你的情况下将是:

const App = () => {
const currentStore = store.getState()
return (
<Provider store={store}>
<h1>{currentStore.title}</h1> // For example
</Provider>
);
}

关于javascript - 是否可以在与 <Provider/> 相同的渲染函数中访问 redux 存储状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54215094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com