import { useEffect, useState } from 'react'; /** * Use React useState hook and update it if initial data change. * * @param initial - The initial value. * @returns The state and a setter. */ export const useStateChange = (initial: T) => { const [state, setState] = useState(initial); useEffect(() => { setState(initial); }, [initial]); return [state, setState] as const; };