Skip to content
RED SAGSkills
medium10 pts · first answer countsreacthookseffects

An effect that re-runs on every render

The effect below runs after every render. Why, and what is the simplest fix?

function Chat({ roomId }) {
  function createOptions() {
    return { roomId, server: "wss://chat.example" }
  }
  useEffect(() => {
    const c = connect(createOptions())
    return () => c.close()
  }, [createOptions])
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions