React

ReactJS Practical Questions - invoke function com...

6.

How do you invoke the setStatus function only when the component mounts, using React hooks?

function MyComponent(props) {
  const [status, setStatus ] = useState(false);

  return <h1>Done: {status}</h1>;
}
 componentDidMount(() => {
        setStatus(true);
    });
useEffect(() => {
        setStatus(true);
    });
useEffect((status) => {
        setStatus(true);
    }, []);
useEffect(() => {
        setStatus(true);
    }, []);