title: How to update the state value using setTimeout in React Hooks?
body: <p>Am trying to reset the state value after some time using setTimeout function.</p>
  
  <pre><code>const SetTimeout = props =&gt; {
    let [errorText, setError] = useState(
      props.errorMessage ? props.errorMessage : ""
    );
    useEffect(() =&gt; {
      if (errorText !== "") {
        setTimeout(() =&gt; {
          setError("");
        }, 4000);
      } else {
        // console.log("no error")
      }
    }, [errorText]);
    return &lt;div&gt;{errorText}&lt;/div&gt;;
  };
  
  const MapStateToProps = state =&gt; {
    return {
      errorMessage: state.errorReducer.error
    };
  };
  </code></pre>
  
  <p>Am getting the <code>errorMessage</code> from an api call, after some time i'm trying to make that message to empty using useState.</p>
  
  <p>But the component is getting re-rendered with the same error message. could you please help me in fixing this?</p>