How to write an effect that depends on a store property?

I would like to scroll to the bottom of the list every time a list changes. My list is a property of a store. I would like to write something like
createEffect(
on([props.list], () => {
scrollIntoView();
})
);
createEffect(
on([props.list], () => {
scrollIntoView();
})
);
but on only accepts type Accessor. Is there another way to do this?
7 Replies
REEEEE
REEEEE•16mo ago
on(() => props.list ...
north korean supermarket
north korean supermarketOP•16mo ago
I get a runtime type error when i try that
Uncaught TypeError: ({get 0() => target[$PROXY][property], get 1() => target[$PROXY][property]}) is not a function
Uncaught TypeError: ({get 0() => target[$PROXY][property], get 1() => target[$PROXY][property]}) is not a function
REEEEE
REEEEE•16mo ago
Could you show the updated code?
north korean supermarket
north korean supermarketOP•16mo ago
createEffect(
on(
() => props.list,
() => {
scrollIntoView();
}
)
);
createEffect(
on(
() => props.list,
() => {
scrollIntoView();
}
)
);
REEEEE
REEEEE•16mo ago
hmm that should be fine 🤔 the issue could be somewhere else?
north korean supermarket
north korean supermarketOP•16mo ago
createEffect(
on([() => props.list], () => {
scrollIntoView();
})
);
createEffect(
on([() => props.list], () => {
scrollIntoView();
})
);
this works for some reason thank you for you help 🙂
shogun2077
shogun2077•16mo ago
Thanks for catching this. I'll make sure to try test this out and add correct the docs
Want results from more Discord servers?
Add your server