From the course: Learning Next.js

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Using dynamic routes and user's input to query content

Using dynamic routes and user's input to query content

From the course: Learning Next.js

Using dynamic routes and user's input to query content

- [Instructor] Now we continue with the demonstration of getServerSideProps here with this dynamic route. There's just one thing I'd like to show you. So before we actually get to the part where we need to make an API call from the New York Times API again. So you're going to notice that we are using here a handler. So I decided to move this function which is to make the API call in a separate module, because it's always good practice to never make any API call in a React component. So I decided to move it here in this location. And the other benefit is that, this is reusable helper function this time. So you can use it wherever and whenever you'd like. And so that's always good practice to separate concerns. So now you've got this handler that you can use. So this is cleaner. And we're going to do the same here in query. We're going to use the search. So we're going to get a response back by using this search…

Contents