RECT/REDUX更新和访问状态值
如何更新本地状态,然后访问同一函数范围内的更新值?
我正在尝试更新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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我理解的。则组件的状态 - >更新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.