useTimeout

    API

    import useTimeout from '@restart/hooks/useTimeout'
    • useTimeout() => object

      Returns a controller object for setting a timeout that is properly cleaned up once the component unmounts. New timeouts cancel and replace existing ones.

      const { set, clear } = useTimeout();
      const [hello, showHello] = useState(false);
      //Display hello after 5 seconds
      set(() => showHello(true), 5000);
      return (
      <div className="App">
      {hello ? <h3>Hello</h3> : null}
      </div>
      );

      Return Value object