Skip to content
Discussion options

You must be logged in to vote

Sorry about missing this!

There was a bug in useSelector where it was re-rendering even if the return value was unchanged. That should be fixed now in the latest version.

Also, for what it's worth, the selection setting could be optimized - that checks all elements in the array twice (includes and filter) and allocates four new arrays. It would be better (and shorter) to use splice directly on the observable:

const index = state.selection.indexOf(id);
if (index >= 0) {
    state.selection.splice(index, 1);
}

But actually, it would be much more efficient as a Set:

// Create state with Set
const state = observable({ selection: new Set<string>() });
// Getting value is constant time
const ch…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nouman2075
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