Why in the following code useEffect hook uses the curly braces, but without return statement, it still works?

after I read this article When should I use a return statement in ES6 arrow functions, I’m still a little bit confused.Why the following code useEffect uses the curly braces, but without return it still works? Not sure if I misunderstand something.
Here is the example:

import React,{useEffect,useState} from "react"

function App() {
  const [resourcetype,setresourcetype]=useState("posts")

  
  useEffect(()=>{
    console.log("render")
  },[resourcetype])
  
  return (
    <div>
      <button onClick={()=>setresourcetype("try")}>try</button>
      <button onClick={()=>setresourcetype("unknown")}>unknown</button>
    </div>
  );
}

export default App;

1 thought on “Why in the following code useEffect hook uses the curly braces, but without return statement, it still works?”

Leave a Comment