title: LocalStorage not updating property in state with React hooks
body: <p>I'm trying to update an object property previously declared in a useState hook for form values and save it in localstorage. Everything goes well, but localstorage is saving date property empty all the time, I know that it must be because of asynchrony but I can't find the solution. This is my code. I'm newbie with React hooks. Lot of thanks!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  const [formValues,setformValues] = useState(
      {
        userName:'',
        tweetText:'',
        date:''
      }
    )
  
    const getlocalValue = () =&gt; {
      const localValue = JSON.parse(localStorage.getItem('tweetList'));
      if(localValue !== null){
        return localValue
      } else {
        return []
      }
    }
  
    const [tweetList,setTweetList] = useState(getlocalValue());
  
    const handleInput = (inputName,inputValue) =&gt; {
      setformValues((prevFormValues) =&gt; {
        return {
          ...prevFormValues,
          [inputName]:inputValue
        }
      })
    }
  
    const handleForm = () =&gt; {
      const {userName,tweetText} = formValues;
      if(!userName || !tweetText) {
        console.log('your tweet is empty');
      } else {
        setformValues(prevFormValues =&gt; {
          return {
            ...prevFormValues,
            date:getCurrentDate() //this is not updating in local
          }
        })
        setTweetList(prevTweets =&gt; ([...prevTweets, formValues]));
        toggleHidden(!isOpen)
      }
  
    }
    console.log(formValues) //but you can see changes outside the function
  
  
    useEffect(() =&gt; {
      localStorage.setItem('tweetList', JSON.stringify(tweetList));
    }, [tweetList]);</code></pre>
  </div>
  </div>
  </p>