"chore: update frontend dev script to include lint checks and add ESLint config file"
This commit is contained in:
32
03_source/mobile/src/hooks/use-set-state.ts
Normal file
32
03_source/mobile/src/hooks/use-set-state.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Custom hook to manage state with utility functions to set state, set a specific field, and reset state.
|
||||
*
|
||||
* @param {T} initialState - The initial state value.
|
||||
*
|
||||
* @returns {UseSetStateReturn<T>} - An object containing:
|
||||
* - `state`: The current state.
|
||||
* - `resetState`: A function to reset the state to the initial value.
|
||||
* - `setState`: A function to update the state.
|
||||
* - `setField`: A function to update a specific field in the state.
|
||||
*
|
||||
* @example
|
||||
* const { state, setState, setField, resetState } = useSetState({ name: '', age: 0 });
|
||||
*
|
||||
* return (
|
||||
* <div>
|
||||
* <p>Name: {state.name}</p>
|
||||
* <p>Age: {state.age}</p>
|
||||
* <button onClick={() => setField('name', 'John')}>Set Name</button>
|
||||
* <button onClick={resetState}>Reset</button>
|
||||
* </div>
|
||||
* );
|
||||
*/
|
||||
type UseSetStateReturn<T> = {
|
||||
state: T;
|
||||
resetState: (defaultState?: T) => void;
|
||||
setState: (updateState: T | Partial<T>) => void;
|
||||
setField: (name: keyof T, updateValue: T[keyof T]) => void;
|
||||
};
|
||||
declare function useSetState<T>(initialState?: T): UseSetStateReturn<T>;
|
||||
|
||||
export { type UseSetStateReturn, useSetState };
|
Reference in New Issue
Block a user