CodePark/ questions / Effects
START PRACTICINGPRACTICE
Frontend question · React › Effects

The app is wrapped in <StrictMode> and running in development. What is logged when Chat mounts?

function Chat() {
  useEffect(() => {
    console.log('connect');
    return () => console.log('disconnect');
  }, []);
  return <h1>Chat</h1>;
}
connect, disconnect, connect

It logs connect, disconnect, connect. In development, StrictMode runs an extra setup and cleanup cycle on mount. This reveals missing cleanup. So you see setup, cleanup, setup. A single connect is what production logs.

"
connect, connect" is the tempting wrong answer. The cleanup always runs between the two setups, so two connect lines in a row never happen.