useReducer vs createReducer
Hello! What are the pros and cons of
1. the
useReducer
in the tutorial (https://www.solidjs.com/tutorial/stores_immutable -> scroll down in the left pane), vs
2. createReducer
from @solid-primitives/reducer
1) is built on createStore
while 2) is built on createSignal
(source)
If I'd want to put a normal JS object with a couple of fields in it to store some state... which one is recommended? thanks!3 Replies
The differences are the differences between stores and signals imo. useReducer will apply changes to objects and arrays granuarly while createReducer won't
@apollo79 thanks for the reply! I'm fairly new to solid, but that seems to suggest that useReducer is the superior solution for the very common case of having nested structure in there? I'm wondering though why solid-primitives chose to go the other way then? Because usually I'd opt to use a solid-primitive over copying something from a tutorial... perhaps I should ask on https://github.com/solidjs-community/solid-primitives/discussions ?
The only reason I can imagine is that using
reconcile
is probably more expensive, bit I don't know how much. You can ask in #solid-primitives too 👍