beekai-oss / little-state-machine

📠 React custom hook for persist state management
https://lrz5wloklm.csb.app/
MIT License
1.48k stars 53 forks source link

Code Sample in TS is not working correctly #128

Closed tuppers360 closed 2 years ago

tuppers360 commented 2 years ago

When cloning the code sample from Code Sanbox (wild-dawn-ud8bq) you have to submit the form twice for the state to update?

Using: import { GlobalState } from 'little-state-machine'; export function updateFirstLastName( state: GlobalState, payload: { firstname: string; lastname: string; } ) { console.log('state before:', state); console.log('payload:', payload); return { ...state, yourDetails: { ...payload, }, }; }

and

const onSubmit = (data: FormValues) => { actions.updateFirstLastName(data); console.log('state after:', state); };

this shows when changing any field it requires submission twice even when the payload is correct. I hope this is correct how I have gone about this.

bluebill1049 commented 2 years ago

which codesandbox?

tuppers360 commented 2 years ago

Sorry it is https://codesandbox.io/s/wild-dawn-ud8bq

bluebill1049 commented 2 years ago

it's working fine for me. after click on submit and refresh the button and the data persist correctly.

tuppers360 commented 2 years ago

apologies for the delay, thanks for checking :-)

its works for me now too, must have been seeing things! sorry to have been a pain thought I was trying to help