Can return a new state object to override initial values
Perfect for setting up derived state or initial data from props
This makes onInit particularly useful when you need to perform calculations or transformations on your initial state before your component starts using it.
1import type { CTAState, } from'./CTAState';
2import type { CTAHistory, } from'./CTAHistory';
3import type { UseCTAReturnTypeDispatch, } from'./UseCTAReturnTypeDispatch';
45export type UseCTAReturnType<
6 Initial extends CTAState,
7 Actions,
8 ReturnValue = void,
9> = [
10 CTAHistory<Initial>, // current state11 UseCTAReturnTypeDispatch<Initial, Actions, ReturnValue>, // dispatcher12];
useCTA returns a type-safe array with two elements for managing complex state operations while maintaining access to state history and change tracking.
Replaces all current property values with new property values.
dispatch.cta.reset
// Reset the state to the initial statedispatch.cta.reset();// sets the current state and initial state to payloaddispatch.cta.reset(CTAState);// sets the current state and initial state to what is returned from the callback// if the callback returns undefined, the state will not changedispatch.cta.reset(( ctaHistory:CTAHistory<CTAState>)=>CTAState|undefined);
Alternate dispatch.cta.reset
// Reset the state to the initial statedispatch({ type:'reset',});// sets the current state and initial state to payloaddispatch({ type:'reset', payload:CTAState});// sets the current state and initial state to what is returned from the callback// if the callback returns undefined, the state will not changedispatch({ type:'reset',payload:( ctaHistory:CTAHistory<CTAState>)=>CTAState|undefined});
Resets the current state back to the initial state or to synchronize the current state and the initial state.