Little State Machine Versions Save

šŸ“  React custom hook for persist state management

v4.8.0

1 year ago

Context

The new method will retrieve the latest store value when an action is performed, this is great for usage such as re-render is not required and yet you want to retrieve the newest store value.

Example

const update  = (state: GlobalState, payload: string) => {
  return {
    ...state,
    value: payload
  }
}

const { getState, actions } = useStateMachine({
  update,
});

<button onClick={() => actions.update('test', { skipRender: true })}>Update<buttonā‰„ 
<button onClick={() => getState()}>Get State<buttonā‰„ 

v4.7.0

1 year ago
  • introduce persist none option which you can skip saving data into session storage and this package can be use with React Native with this config set to none as well
createStore(
  {
    yourDetail: { firstName: '', lastName: '' } // it's an object of your state
  },
  {
     // when 'none' is used then state is not persisted
     // when 'action' is used then state is saved to the storage after store action is completed
     // when 'beforeUnload' is used then state is saved to storage before page unload and is restored
     // after next page load and then storage is cleared
     persist?: 'action' // onAction is default if not provided
  },
);

huge thanks to @snax4a

v4.6.0

1 year ago
  • add new option for skip context re-render
const { actions } = useStateMachine()

// The following action will only update the store without flushing down a context re-render update
actions.updateStore({
  test: 'data'
}, { skipRender: true })

v4.4.1

1 year ago

4.4.1 (2022-05-29)

Bug Fixes

v4.4.0

1 year ago

4.4.0 (2022-05-29)

Features

v4.2.4

2 years ago

type update: allow actions payload to be optional

export type ActionsOutput<
  TCallback extends AnyCallback,
  TActions extends AnyActions<TCallback>
> = {
-  [K in keyof TActions]: (payload: Parameters<TActions[K]>[1]) => void;
+  [K in keyof TActions]: (payload?: Parameters<TActions[K]>[1]) => void;
};

v4.2.3

2 years ago

fix: type issue with createStore optional argument

v4.2.1

2 years ago

4.2.1 (2022-02-08)

Bug Fixes

v4.2.0

2 years ago

4.2.0 (2021-10-27)

Features

v4.1.2

2 years ago

4.1.2 (2021-06-05)

Bug Fixes