cefn / watchable

Repo for @watchable/store and supporting packages.
MIT License
5 stars 1 forks source link

Consider removing useStore #44

Open cefn opened 9 months ago

cefn commented 9 months ago

The implementation of useStore is just...

export function useStore<T extends RootState>(initialState: Immutable<T>) {
  const [store] = useState(() => {
    return createStore(initialState);
  });
  return store;
}

Perhaps this is so minimal (and such an unnecessary black box) that it should just be removed. Ideally developers would know what they are doing with store identity. Withdrawing this hook would require them to directly consider the approach they are taking. For many applications, a store created outside React altogether is a good option, for example, and eliminates any unexpected behaviours associated with store identity or initial state.