skip to Main Content

Reactjs – How to prevent a React useEffect from running twice in StrictMode development with an external system that has no cleanup method?

Consider the following example: pages/index.js import { useState, useRef, useEffect } from 'react' function complexExternalLibraryFunctionWithoutCleanup(elem, cb) { elem.addEventListener('click', () => { cb() }) } export default function IndexPage() { const [text, setText] = useState('') const [myint, setMyint] = useState(0) const…

VIEW QUESTION
Back To Top
Search