useEffect not working when mixed with useState #1014
-
Bug Descriptionclick the
import React, { useCallback, useEffect, useState } from 'react';
import { proxy, useSnapshot } from 'valtio';
const obj = proxy({ a: 'a' });
export const Test = () => {
const { a } = useSnapshot(obj);
const [b, setB] = useState('b');
const handleClick = useCallback(
() => {
setB('b');
obj.a = `${a}a`;
},
[a],
);
useEffect(
() => {
console.log('a changed');
},
[a],
);
console.log('render:', a);
return (
<div>
<div>{a}</div>
<button onClick={handleClick}>click</button>
</div>
);
};
Reproduction Link |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Dec 16, 2024
Replies: 1 comment 1 reply
-
I'm not sure if this bug persists in v2, but v2 doesn't support react < 18 anyway.
That sounds like a reasonable workaround if that solves. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
GuessEver
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure if this bug persists in v2, but v2 doesn't support react < 18 anyway.
So, I guess this bug is something we won't fix.
That sounds like a reasonable workaround if that solves.