Replies: 1 comment 2 replies
-
Why not write a custom hook with two useQuery calls and |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using RTK with msw to mock responses in tests suite. Everything works well until there's a selector in some component trying to select data from redux store before there was a query made which was not mocked yet.
It's very brittle and unergonomic to manually force query to be made before test is run so the selector used already filled in data.
So far there was used
jest
test runner with mocks for selectors which I'd like to avoid and go with msw exclusively.Selectors are actually a derived queries in my view, selectors depend on some previous state which should be established beforehand. That's why I think
createDerivedRTKQuery
helper would be desirable, see an example:Implementation of
createDerivedRTKQuery
is quite simple, it's basically running hooks in the for loop with applied arguments and conforming to type of query so hooks created withcreateDerivedRTKQuery
can be deeply composed. Running hooks in for loop is totally safe assuming there is constant number of iterations - we have it here.Is this idea well grouned, do you suggest other solutions instead?
Beta Was this translation helpful? Give feedback.
All reactions