繁体   English   中英

为什么控制台日志显示 redux State 的一个值而屏幕呈现另一个值?

[英]Why console log shows one value for redux State and the screen renders another?

我将创建一个虚构的示例来公开我的问题,因为我无法分享我的代码:

Let's suppose that I'm on a SCREEN B and I have a redux state called 'name' with the current value setted to "Paul", and after I click on a button in this screen I use dispatch to change the redux state value to “菲利普”。

Let's suppose also that I have a SCREEN A that always shows me in console with useEffect the value of my 'name' redux state that I get from useSelector() hook, and also in this screen I have one text that render this same redux state价值。

当我在屏幕 B 上并使用按钮更改“名称”state 的值时,然后当我回到屏幕 A 时,console.log 显示值“Paul”(旧值),但我的文本呈现值“菲利普”(新值)。 为什么会发生这种情况? 我坚持认为,一旦我更新了我的 state,它就应该显示控制台日志并呈现新信息......

谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM