React Server Components (RSC) is a new way to build server-rendered applications with React. It is a set of experimental tools that enables developers to run React components on the server. RSC is a new way to build server-rendered applications with React.
Using server actions with existing graphQL mutations and queries works well and moves away from wrapping the app / layout file in a context provider / using hooks provided by apollo-client.
The idea is we can have a server component link to the graphQL endpoint and the server actions can be called directly from the UI. This moves away from either needing to using axios from a React Class Component, or using the API routes to make a request that needs to be returned to the client.
We can build upon the GraphQL library of mutations, queries and fragments we have made and adopt this new architecture which is modular and type safe throughout.
This allows us to move quickly and have the best of server rendered data with client side interactiveness depending on the use case.
We can now fetch the individual return data using /return/[id]/page.tsx which is a server component. This makes an aysnc call to the Stateset One GraphQL API on Stateset Cloud which we have typed return operators for.
We are already starting to see the benefits of using this pattern in that we can still have the declarative side of GraphQL but we have a much cleaner approach than have queries stored on each JS file. We can keep all of them in ‘lib/stateset’ and import them to the server actions files that we need.
We can also use fragments to keep the queries clean and modular. This is a great way to keep the queries clean and also to keep the types consistent across the application.
We can now use the server actions to call the GraphQL API and return the data to the server component. This is a great way to keep the queries clean and also to keep the types consistent across the application.
We can now use the server component to fetch the data and return it to the client. This is a great way to keep the queries clean and also to keep the types consistent across the application.