Comments (3)
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 obj
itself.
const { obj: snap } = useSnapshot(it);
from valtio.
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
obj
itself.const { obj: snap } = useSnapshot(it);
Can I do something like replace the value to fix this?
Maybe I can make a PR to implement this replacement function and include it in valtio if this is reasonable;
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;
});
from valtio.
It's a reasonable practice but you don't need to make a PR for that.
There are many other libraries that do similar things.
Feel free to submit a PR to improve docs.
from valtio.
Related Issues (20)
- `use-sync-external-store` should be marked as a `peerDep` HOT 7
- synchronous partial state update Interface HOT 1
- Consuming a valtio proxy from another package results in "TypeError: proxyState is not iterable" HOT 1
- Cache key could refer previous value HOT 18
- About Rerendering ๏ผIs it a bug or my usage error๏ผRequest help HOT 1
- There is a defect in the ref in proxyWithHistory HOT 1
- Typescript & devtools HOT 1
- Vanilla `subscribe` does not trigger when a computed getter is updated HOT 2
- Branded primitive types are incompatible with Snapshot<T> HOT 8
- Snapshots can be mutated by adding or removing properties HOT 2
- bug when filtering data
- defineProperty trap makes property non-CEW in React Native (Hermes engine) HOT 10
- proxyState is not iterable
- tsc fails when using functions in valitio/utils
- use class throw error
- [Warning] Please install/enable Redux devtools extension
- Support option to disable render optimization in useSnapshot HOT 1
- Performance Degradation in proxySet Instances with Increased Keys. HOT 1
- Why my code doesn't work, just getter/setter, cause ui cannot listen the state change
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from valtio.