Skip to content
Discussion options

You must be logged in to vote

so, in summary:

  • run it in the queryFn - it will be executed on every fetch, even if data didn't change, because it happens before structural sharing
  • run in as select - it will run once for every subscriber

The solution would be to introduce another caching that memoizes the transformation outside of react by its input so that you use it for select, but run it only once. reselect works well for that, and your shown code is exactly how I would do it / have done it in the past:

const computedData= createSelector(
  data => data,
  expensiveTransform,
)

👍

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
4 replies
@magbicaleman
Comment options

@louis-young
Comment options

@magbicaleman
Comment options

@louis-young
Comment options

Comment options

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

Answer selected by magbicaleman
Comment options

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

Comment options

You must be logged in to vote
3 replies
@TkDodo
Comment options

@pastinepolenta
Comment options

@TkDodo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants