title: How to use callback with useState hook in react
body: <p>I am using functional component with hooks. I need to update state in parent from a child. I am using a prop function in Parent. 
  All works fine except my prop function is getting the previous state and not the current state. My prop function gets executed before <strong>useState</strong> hook setting current state.
  How can I can I wait for my call back function to be executed after useState call. I am looking for something like <strong>setState(state,callback)</strong> from class based components.</p>
  
  <p>Here is the code snippet:</p>
  
  <pre><code>function Parent() {
    const [Name, setName] = useState("");
    getChildChange = getChildChange.bind(this);
    function getChildChange(value) {
      setName(value);
    }
  
    return &lt;div&gt; {Name} :
      &lt;Child getChildChange={getChildChange} &gt;&lt;/Child&gt;
    &lt;/div&gt;
  }
  
  function Child(props) {
    const [Name, setName] = useState("");
    handleChange = handleChange.bind(this);
  
    function handleChange(ele) {
      setName(ele.target.value);
      props.getChildChange(collectState());
    }
  
    function collectState() {
      return Name;
    }
  
    return (&lt;div&gt;
      &lt;input onChange={handleChange} value={Name}&gt;&lt;/input&gt;
    &lt;/div&gt;);
  } 
  </code></pre>