In this section, we'll implement REST API calls using axios in a function component. We'll refactor the App component we built in the last section:
- First, we are going to declare a constant, called defaultPosts that is going to hold the default posts state we'll use a little later. We'll add this after the IPost interface and set this to an empty array:
const defaultPosts: IPost[] = [];
- We'll remove the IState interface because the state will be structured as individual pieces of state now.
- We'll also remove the previous App class component.
- Next, let's start the App function component under the defaultPosts constant:
const App: React.SFC = () => {}
- We can now create the state for the posts, error, ...