transform() option #2405
Unanswered
rentalhost
asked this question in
Ideas
Replies: 1 comment 1 reply
-
Have you looked into middleware yet? https://swr.vercel.app/docs/middleware From the docs:
Perhaps you can do your transformation in the "before" state as it mentions? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a use case where I need to transform the data received by the fetcher before it is delivered by the SWR. Well, I could do it in the fetcher itself, but since my fetcher is so simple, I can reuse it in many places, whereas a
transform()
is exceptional.In my case, the data that I get from the server is disorganized, and I want to keep it in alphabetical order. So I needed to use SWR and do an intermediary
useMemo()
for that, however, I have two copies of pretty much the same information.Currently:
Possible solution modifying fetcher: but in this case, I need to maintain several fetchers or generate greater complexity in them for something that I think would be essential to be the responsibility of the SWR.
Feature request:
Beta Was this translation helpful? Give feedback.
All reactions