beekai-oss / little-state-machine

📠 React custom hook for persist state management

Home Page:https://lrz5wloklm.csb.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Actions always trigger useEffect when in dependencies

rpk-red opened this issue · comments

commented

I have useEffects in my codebase that have little-state-machine actions as dependencies, everything worked fine until I update little-state-machine from version "3.1.2" to 4.1.0. Now Actions call every time useEffect and re-render my components.
Also tried with TS demo sample from your docs, only added this effect :
useEffect(() => { console.log("called every time"); actions.updateFirstLastName({ yourDetails: { firstname: "testFirst", lastname: "testLast" } }); }, [actions]);
in Form.tsx file. And got same result.

Not sure what to do, can someone help?

commented

@bluebill1049 > I don't think it's the correct behaviour: https://codesandbox.io/s/little-state-machine-demo-forked-90vmo?file=/src/form.js

You have to call some action inside useEffect also. For example:
actions.updateFirstLastName(...);

thanks, should be fixed in the next patch.

commented

@bluebill1049 can you tell me when will next patch be released? Or if you can tell me what is highest package version that has no such bag?

can you try with the latest?

commented

@bluebill1049 I updated to version 4.1.1 and it still has the same issue.

commented

It works now! Thank you for fast response. :)