-
Lets say I have huge data array with complicated nested objects I fetch from http and I want to filter it using the state in valtio. Like const state = proxy({ showType: "foo", data: [] });
async getData() {
const res = await fetch(...)
state.data = (await res.json()).data
}
function Component() {
const snap = useSnapshot();
return (
<ul>
{snap.data.filter(item => item.type === snap.type).map(item =>{
return <li>{item.title}</li>
})}
</ul>
)
} I never modify modify Can Valtio cause meaningful overhead since it will deeply wrap the Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Jun 9, 2021
Replies: 1 comment 1 reply
-
Yes, use async getData() {
const res = await fetch(...)
state.data = ref((await res.json()).data)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
esamattis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, use
ref()
.