Apply What You Learned
Now that you know about effects, you can add even more exciting features to your React apps. Fetching data via HTTP upon rendering a component is just as easy as accessing browser storage when some state changes.
In the following section, you'll find an activity that allows you to practice working with effects and useEffect()
. As always, you will need to employ some of the concepts covered in earlier chapters (such as working with state).
Activity 8.1: Building a Basic Blog
In this activity, you must add logic to an existing React app to render a list of blog post titles fetched from a backend web API and submit newly added blog posts to that same API. The backend API used is https://jsonplaceholder.typicode.com/, which is a dummy API that doesn't actually store any data you send to it. It will always return the same dummy data, but it's perfect for practicing sending HTTP requests.
As a bonus, you can also add logic to change the text...