From the course: React Essential Training
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Passing data as props - React.js Tutorial
From the course: React Essential Training
Passing data as props
- [Instructor] We've gotten to see how all of our components by default in an XJS application are server components. This means that they're going to be server rendered as HTML, and then anything that is going to be interactive, we need to handle that in a slightly different way. So we're going to make some adjustments here specifically to our hotels component. And this component is going to start to introduce us to some of these different concepts. Now, the first thing I want to do here is I want to create an asynchronous function. This time we need to load some data for this page. So we're going to grab it like we did before. So we'll say const res equals await fetch. So our response is going to fetch from https, snowtooth-hotel-api.fly.dev. Okay, and once we do that, we can return response.json. So make the request and return it as JSON. Just like we did before, we are to use a $100,000 word, co-locating our request with our component. So we are going to grab it here, getData. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.