RECT/REDUX更新和访问状态值

发布于 2025-02-11 21:50:56 字数 247 浏览 0 评论 0原文

如何更新本地状态,然后访问同一函数范围内的更新值?

我正在尝试更新Redux的商店, 我正在从当地状态中获得价值, 我正在从状态更新中的同一功能范围内部进行此操作。 当我这样做时,局部状态的预先更新的值正在传递给商店,

我尝试在监视状态的代码中添加使用效果,以使其试图使其更新函数范围中的状态值,但是它行不通。

因为我们有一个按钮一次执行所有操作,所以它全部包裹在一个函数中。 我敢肯定,解决方案正在使用异步/等待,但是我对此并不那么热!

How can I update a local state and then access the updated value within the same function scope?

I am trying to update the store in redux,
I am taking values from a local state,
I'm doing this from inside the same functional scope that the state is being updated in.
when I do this, the pre-updated value of the local state is being passed to the store

I have tried adding a useEffect to the code which watches the state to try and make it update the value of the state in the function scope, but it doesn't work.

Because we are having one button do everything at once, it is all wrapped in one function.
I'm sure the solution is using async/await, but I am not so hot with that!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲在坟头点根烟 2025-02-18 21:50:56

我理解的。则组件的状态 - >更新Redux商店,然后阅读商店。您应该做的是:创建一个动作以更新商店,使用React-Redux派遣操作。 https://react-react-react-react-readux.js.org/api/api/connect
使用MapStateToprops读取商店状态并将其在组件中使用。

What I understood. State of Component then -> update Redux Store, then read the store. What you should do is: Create an action to update the store, use react-redux to dispatch the action. https://react-redux.js.org/api/connect.
Use mapStateToProps to read the store state and use it in your component.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文