2021年4月24日星期六

My reducer is triggered twice when I call it once. There something strange when I try to fix it

Here is my code. The demo site is here.

On the demo web page, I have 2 buttons, 1 is the "go" button, the other one is the "Back" button, when I click on the "go" button, the console will show the state and action twice. So, I try to use the useEffect hook to fix the problem.

  useEffect(()=>{         flag=true;    },[dispatch])  

Although it can solve the "go" button problem, when I click on the "Back" button, the reducer cannot print the state and action to the console. How can I fix the problem?

https://stackoverflow.com/questions/67248857/my-reducer-is-triggered-twice-when-i-call-it-once-there-something-strange-when April 25, 2021 at 09:06AM

没有评论:

发表评论