Examples should demonstrate best practice with scope of selector creation..
Looking at e.g. the following line...
|
const counter = useSelected(counterStore, (state) => state.counter); |
...the selector is recreated on every render. This goes against advice from the docs.
Although this doesn't create more renders, the render is doing more work than necessary, since the evaluation of the (new) selector can't be skipped, which could be skipped if the selector reference remained unchanged (e.g. was created with module scope).