Noob question: createRenderEffect vs createEffect or onMount
This is mainly a dev experience question. I feel like I understand the differences between these but honestly I just find myself always opting to use createRenderEffect over onMount or createEffect and unsure what scenario I would use them over createRenderEffect.
Perhaps the wrong way to think about it but I usually think "createRenderEffect runs before the others and I want my code to be ran as soon possible so I will use this over the others".
What is the right way to think about createRenderEffect and why would I opt to use onMount or createEffect over it. (I know createRenderEffect vs createEffect is more of the question as onMount is technically more explicitly different but curious nonetheless why)
4 Replies
onMount will only ever run once per rendered component. createEffect will run with a relaxed timing to ensure refs should be filled. createRenderEffect runs before that, so you'll likely miss a ref on the first run.
Hmm so here I notice the difference between them here:
https://discord.com/channels/722131463138705510/1098872623762526339/1098872623762526339
Not sure why though as I do not think
itemsCount
is a ref, right?A ref is just a function being called before the parent's createEffect runs.
So is there a way to update one on client prior to being rendered with init val being localstorage