From the course: React: Working with APIs (2018)
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Challenge: Refactor component for reuse - React.js Tutorial
From the course: React: Working with APIs (2018)
Challenge: Refactor component for reuse
- [Narrator] Before we move on to learn about more techniques to fetch API's, let's refactor our application a little bit, so we can reuse the same component to get different data. Here is what I want to be able to do. I want to be able to pass, at the App.js level, different variables, or different settings, into a component that's reusable, and that component will be the news. And we'll refactor news to be able to reuse this particular component for any type of news that we would like to get. So for example, I'd like to be able to pass some variables that will change the URL here, and what I want to change is this section here. So I want to be able to actually this section. So I want to be able to change these items so if you went back to newsapi.org, by changing this section, you should be able to get different news, and then get a brand new state with the news and then this shouldn't have any impact here. So you should be able to basically render the same news based off the data…
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.