title: Why is my useEffect not running on first render?
body: <p>So I am trying to scramble a sentence or string and push the words into an array to later join them and output this scrambled sentence but for some reason the useEffect is not running on the first render even with an empty array but when I change one line and run it again it runs as intended. I was just wondering if I was doing anything wrong and how I can change it so that it does run on the first render.</p>
  <pre><code>const ScrambleSentence = ({sentence}) =&gt; {
      const [words, setWords] = useState([]);
      const [scrambledSentence, setScrambledSentence] = useState('');
      let scrambledWord = [];
  
  
      function scrambleWord(n){
          var text = n.split('');
          for(var i = text.length - 1; i &gt; 0; i--){
              var j = Math.floor(Math.random() * (i + 1));
              var temp = text[i];
              text[i] = text[j];
              text [j] = temp;
          }
          return text.join('');
      }
  
      useEffect(() =&gt; {
          setWords(sentence.split(' '));
  
  
          words.map(word =&gt;{
            if(word.length &lt;= 2){
              scrambledWord.push(word);
  
            }
            else{
              scrambledWord.push(scrambleWord(word));
            }
          })
          setScrambledSentence(scrambledWord.join(' '));
        }, [])
  
  
        console.log(scrambledSentence);
      return (
          &lt;div&gt;
              &lt;p id='scrambled-word'&gt;{scrambledSentence}&lt;/p&gt;
          &lt;/div&gt;
      )
  };
  
  export default ScrambleSentence;
  </code></pre>