Skip to content

Memoizing selectors for actions #312

Closed Answered by dai-shi
zbeyens asked this question in Q&A
Discussion options

You must be logged in to vote

I'd say it's a subtle difference and you can do either way.
If you are keen about the performance, it's still creating an object and shallow compare it in every render.

More performant way is:

const actions = {
  setValue: useStore.getState().setValue,
  setComponents: useStore.getState().setComponents,
  setEditor: useStore.getState().setEditor,
  setPlugins: useStore.getState().setPlugins,
};

Or, not defining actions in the store in the first place. But, again it would be a subtle difference and you wouldn't notice unless benchmarking in artificial settings.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zbeyens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants