@tremendous/help
    Preparing search index...

    Function useSafeState

    • Custom hook to manage state that only updates if the component is still mounted.

      This hook provides a stateful value and a function to update it, ensuring the state is only updated if the component is still mounted, avoiding potential memory leaks.

      Type Parameters

      • T = undefined

      Parameters

      • OptionalinitialState: T | (() => undefined | T)

        The initial state value or a function that returns the initial state.

      Returns SafeSetState<T>

      • The current state and a function to safely update the state.
      const [value, setValue] = useSafeState(0);

      useEffect(() => {
      setTimeout(() => {
      setValue(1); // This will only run if the component is still mounted
      }, 1000);
      }, [setValue]);