Open ingoandelhofs opened 2 years ago
const name = value({ firstName: "John", lastName: "Doe", age: 34 });
// This component will only update when firstName changes const firstName = usePartial(name, ["firstName"]); return <div>{firstName}</div>
// Alternative const firstName = usePartial(name, (name) => name.firstName); return <div>{firstName}</div>
// Alternative const {fn, ln}= usePartial(name, (name) => {fn: name.firstName, ln: name.lastName}); return <div>{fn} {ln}</div>
We can refactor to only have the useValue hook?
useValue
// Alternative const {fn, ln}= useValue(partial(name, (name) => {fn: name.firstName, ln: name.lastName})); return <div>{fn} {ln}</div>