Corné Dorrestijn

Two counters

Here are two counters, both are made with signals. One is a signal defined outside of this component. One signal is defined inside this component. By defining the signal a single line higher, you get the option to keep state. But, is this a good thing or a bad thing?

Here is the counter that is defined outside of the component. Its state will stay the same when you navigate to other pages: 0

Here is the counter that is defined inside the component. Its state will reset when you navigate to other pages: 0

This is not possible using React hooks, but it can also lead to bad spaghetti code when overused. It also feels a lot more like magic.