title: How can I pass data to an object using React Hooks and Redux
body: <p>I am trying to pass data that I get from a data base to an object, using react and redux.
  I cant figure out  what Im doing  wrong</p>
  <p>This is my code</p>
  <pre><code>const [orders, setOrders] = useState([]);
  
  useEffect(() =&gt; {
      props.fetchOrder(setOrders);
  }, []);
  
  console.log(orders);
  
  const columnsFromBackend = {
      newOrder: {
          name: &quot;Requested&quot;,
          items: orders
      },
      x: {
          name: &quot;x&quot;,
          items: []
      }
  };
  const [columns, setColumns] = useState(columnsFromBackend);
  
  console.log(columns);
  </code></pre>
  <p>the result is the page renders twice, in the console it shows, fir</p>
  <blockquote>
  <p>orders = []</p>
  </blockquote>
  <blockquote>
  <p>columns = {newOrder: {…}, x: {…}}</p>
  </blockquote>
  <p>in the second time</p>
  <blockquote>
  <p>orders = (39) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]</p>
  </blockquote>
  <blockquote>
  <p>columns = {newOrder:
  items: []}</p>
  </blockquote>
  <p>the items property inside newOrder object should have been equal to orders, but it stayed  empty</p>
  <p>How do I pass into the items property the data of orders correclty?</p>
  <p>just for clearance, this is the fetch function from the redux actions</p>
  <pre><code>export const fetchOrder = setOrders =&gt; dispatch =&gt; {
      fetch(&quot;/api/orders&quot;)
          .then(res =&gt; res.json())
          .then(data =&gt; {
              setOrders(data);
              dispatch({ type: FETCH_ORDER, payload: data });
          });
  };
  </code></pre>
  <p>Thank  you and have a nice day</p>