Wrapper around zustand store to allow you to extract all data separate from methods if needed.
Parameters:
Name | Type | Description |
---|---|---|
data | object | Initial state of store. |
actions | function | Store actions. |
- Since
- 1.0.0
- Source
Returns:
- Type:
- *
Example
import { create } from '@gravityforms/react-utils';
import config from 'gform-admin-config';
const initialState = config?.components?.setup_wizard?.data?.defaults || {};
const storeActions = ( set ) => ( {
closeDialog: () => set( () => ( { isOpen: false } ) ),
patchServices: ( checked, e ) => set( produce( ( draft ) => {
draft.services.forEach( ( type, i ) => {
if ( type.value === e.target.value ) {
draft.services[ i ].initialChecked = checked;
}
if ( e.target.value === 'other' && ! checked ) {
draft.servicesOther = '';
}
} );
} ) ),
setActiveStepNext: () => set( ( state ) => ( { activeStep: state.activeStep + 1 } ) ),
setActiveStepPrevious: () => set( ( state ) => ( { activeStep: state.activeStep - 1 } ) ),
} );
const useStore = create( initialState, storeActions );
export default useStore;