Accepted answer

It's because no callback function is being passed into useEffect. In the example above, it is actually executing the fetch request which doesn't return anything. Wrap the fetch call in an arrow/anonymous function and it will work.

function App() {
  const [user, setUser] = React.useState(null);
  React.useEffect(() => { // Pass in a callback function!
      .then(results => results.json())
      .then(data => {
  }, []);
  return <div>
    {user ? : 'Loading...'}

ReactDOM.render(<App/>, document.getElementById('app'));
<script src=""></script>
<script src=""></script>

<div id="app"></div>


useEffect must have a callback function. In this case you can use an arrow/anonymous function inside the brackets. useEffect(()=>{your code})

Related Query

More Query from same tag