function Example() { const f = n=>{console.log('firing '+n); return n;}; const [a, setA] = React.useState(f(0)); // calling a function const [b, setB] = React.useState(()=>f(1)); // passing a raw function return (
{a} {b}
{setA(a+1);}}>firing f(0) on every render
{setB(b+1);}}>firing f(1) on first render only
);}ReactDOM.render(
,document.querySelector("div"));