Introducing a data transformation layer #1202
-
Hi, I was wondering if anyone has any idea on how to integrate something like class-transformer (or similiar solutions) with SWR? If we're talking about using SWR on the client-side, this is pretty straightforward I'd say (a mapper incorporated in the fetcher)... But, if I were to use Next.js with (for example) SSR (getServerSideProps) and the data is populated in the following manner (like in the docs): export async function getServerSideProps() {
const posts = await fetcher('/api/posts')
return { props: { posts } }
}
function Posts (props) {
// Here the `fetcher` function will be executed on the client-side.
const { data } = useSWR('/api/posts', fetcher, { initialData: props.posts })
// ...
} how would you recommend approaching this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can probably take a look at the new Middleware API in #1160, it's still in the beta release but we will have that documented soon. |
Beta Was this translation helpful? Give feedback.
You can probably take a look at the new Middleware API in #1160, it's still in the beta release but we will have that documented soon.