From the course: React: Software Architecture
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Enhancing SSR with context
From the course: React: Software Architecture
Enhancing SSR with context
- [Instructor] All right, the next thing that we're going to do now that we've got our context stuff set up on the server side is create a custom React hook for basically dealing with getting this data out of the context. This will simplify things for our components since our components will no longer have to care whether they're on the server or on the client side. You'll see what I mean in just a minute. So first, let's create new file. We'll call this file useDataSSR.js. And here's what it's going to look like. We're going to start off by importing the useState hook from react. And under that we're going to import our InitialDataContext from InitialDataContext. And then we're going to say export const useDataSSR equals, and this custom hook is going to take two arguments. The first is going to be an argument called resourceName. And the second one is going to be an argument called loadFunc. Okay. So the next thing…