title: Push Object to array in react useState hook
body: <p>I am declaring react state as below</p>
  <pre><code>const [selectedFiles, setselectedFiles] = useState([]);
  </code></pre>
  <p>Using them in function as below</p>
  <pre><code>function handleAcceptedFiles(files) {
      files.map((file) =&gt;
        Object.assign(file, {
          preview: URL.createObjectURL(file),
          formattedSize: formatBytes(file.size),
        })
      );
      setselectedFiles(files);
    }
  </code></pre>
  <p>I am trying to add as below but not working</p>
  <pre><code>selectedFiles.length === 0 ? setselectedFiles(files) : setselectedFiles(oldFiles =&gt; [...oldFiles,files])
  </code></pre>
  <p>but it did not help me.</p>