Wrapper around zustand store to allow you to extract all data separate from methods if needed.

Parameters:
NameTypeDescription
dataobject

Initial state of store.

actionsfunction

Store actions.

Since
  • 1.0.0
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;