Skip to content

promer94/incorrect-memo-fn-nextjs

Repository files navigation

function are not memorized correctly when using react-compiler with next.js

To Reproduce

  1. build the application with next build
  2. start the application with next start
  3. click the numbers to see the console log

function Test1() {
    const [expire, setExpire] = useState(5)
    useEffect(() => {
        const timer = setInterval(() => {
            setExpire((prev) => prev - 1)
        }, 1000)
        if (expire === 0) {
            clearInterval(timer)
        }
        return () => clearInterval(timer)
    }, [expire])
    const onClick = () => {
        console.log('isExpired', isExpired)
    }
    const isExpired = expire === 0
    return <div onClick={onClick} className="text-red-500">{expire}</div>
}

The onClick function should be able to access the latest value of isExpired

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published