Skip to content

Ok to return an array from a selector function? #97

Answered by lostpebble
coffeemug asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @coffeemug ,

Also, will the hook fire on updates to the map, or will it also fire when fields in objects inside the map are updated?

Yep- that should all work fine! It does do a deep-equal comparison on any value returned from the selector passed to useState().

How I would usually do something like this though- to improve performance slightly- is I would map over the ids and return individual components which take an id and then pick out the item they need in useState(s => s.myStuff[id]) - this way, only the components with items which actually change inside your store get re-rendered.

But I can't know exactly what you're trying to do- but generally, selecting more specific state as …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@coffeemug
Comment options

Answer selected by coffeemug
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