-
I'm transitioning from Easy Peasy which has a computed function which allows using state local to the current object and pull in other sections of state. And it remains reactive. We have addresses that are able to be set to active/inactive and the app displays the aggregated assets from all the selected addresses. Here's the function for reference. // assets.ts
addressAssets: computed(
[
(state) => state.addressAssetsByAddress, // 👈 exists in this state (assets).
(_, store) => store.addresses.selectedAddresses // 👈 exists in other piece of state.
],
// 👇 used here.
(addressAssetsByAddress, selectedAddresses) => {
//
let aggregate = [];
selectedAddresses.forEach((address) => {
const addressAssets = addressAssetsByAddress[address.value];
aggregate = [...aggregate, ...addressAssets];
});
return aggregate;
}
), The above code is in the assets state but updates the page when addresses or assets are changed. What is a good approach to something like this using Valtio? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'm an idiot. I already made myself an example. |
Beta Was this translation helpful? Give feedback.
I'm an idiot. I already made myself an example.
https://codesandbox.io/s/react-valtio-with-persisted-state-v4yoy?file=/src/App.tsx:207-219