-
-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace object not trigger render #758
Comments
const snap = useSnapshot(it.obj);
// that ☝️ means like this 👇
const objThatNeverChanges = it.obj;
const snap = useSnapshot(objThatNeverChanges); So, it's how JS works. The canonical fix is to subscribe to const { obj: snap } = useSnapshot(it); |
Can I do something like replace the value to fix this? const it = proxy({
obj: { a: 1 },
});
// just a simple implementation, it may be not work in some situation
const replace = (it, key, value) => {
Object.keys(value).forEach(item => {
it[key][item] = value[item];
});
};
setTimeout(() => {
replace(it, 'obj', { a: 2 });
}, 1000);
const A: React.FC = React.memo(function A(props) {
const snap = useSnapshot(it.obj);
console.log('===========update', snap); // only render once
return null;
}); |
It's a reasonable practice but you don't need to make a PR for that. |
Summary
Link to reproduction
Check List
Please do not ask questions in issues.
Please include a minimal reproduction.
The text was updated successfully, but these errors were encountered: