title: How do I update an object state in react via hooks
body: <p>This is a simple question. How do I successfully update state object via react hooks? </p>
  
  <p>I just started using hooks, and I like how it allows to use the simple and pure JavaScript function to create and manage state with the <code>useState()</code> function, and also, make changes that affect components using the <code>useEffect()</code> function, but I can't seem to make update to the state work!</p>
  
  <p>After making a request to an API, it return the data needed, but when I try to update the state for an error in request and for a successful request, it does not update the state. I logged it to the browser console, but no change was made to the state, it returns undefined.</p>
  
  <p><a href="https://i.stack.imgur.com/kOqtd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kOqtd.png" alt="enter image description here"></a></p>
  
  <p>I know that I'm not doing something right in the code.
  Here is my <code>App</code> component, Its a single component for fetching and updating:</p>
  
  <pre><code>import React, { useState, useEffect } from 'react';
  import ReactDOM from 'react-dom';
  
  
  export default function App() {
  
      // Set date state
      const [data,setData]  = useState({
         data: [],
         loaded: false,
         placeholder: 'Loading' 
      });
  
      // Fetch and update date
      useEffect(() =&gt; {
  
          fetch('http://localhost:8000/api/lead/')
          .then(response =&gt; {
              if (response.status !== 200) {
                  SetData({placeholder: 'Something went wrong'});
              }
              response.json()
          })
          .then(result =&gt; {
             console.log(data);
             setData({data: result});
          });
  
      },[]);
  
      return (
        &lt;h1&gt;{console.log(data)}&lt;/h1&gt;
      );
  }
  
  ReactDOM.render(&lt;App /&gt;, document.getElementById('app'));
  </code></pre>