I then pass the signal into context and use it another file in this function:
const itemsCount = () => { const clen = cart().length; const c = cart(); const clen2 = cart; let sum = 0; if (c) { c.forEach((p, i) => { sum += p.count; }); } return sum; };
const itemsCount = () => { const clen = cart().length; const c = cart(); const clen2 = cart; let sum = 0; if (c) { c.forEach((p, i) => { sum += p.count; }); } return sum; };
I then return it as is standard:
<span> {itemsCount()} </span>
<span> {itemsCount()} </span>
For some reason it does not update if the ternary is set to localStorage although it will update if I change
itemsCount()
itemsCount()
to a signal that I set to
itemsCount()
itemsCount()
in
onMount
onMount
or
createEffect
createEffect
if I use
createRenderEffect
createRenderEffect
to set the signal,
cart()
cart()
will have the desired value and
itemsCount()
itemsCount()
the desired return but it just does not update the DOM.
I know the server is setting the initial page load and I expect it to load as 0 but I would would expect there to be a way for me on the client to update the DOM before mount and avoid the flash to the updated value.
Any ideas if I can solve this or if solvable with source of data being localStorage?