From the course: Building a Website with Laravel, React.js, and Inertia

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Refactoring to components

Refactoring to components

- [Instructor] In the previous video, we displayed a post we fetched from the JSON placeholder API. Everything is looking great, but what we need to do now is to create a new component that will encapsulate this functionality and then import it into our home component. Let's create post directory inside the pages directory and inside there we will create index.jsx component. This component will be responsible for fetching and displaying all posts. In the home component, let's copy everything and paste it into post index component. We need to change the name from home to index and delete the default keyword because we will be importing this component as post not as index. Then we will delete the heading and only keep the post loop. In the home component we will delete the hooks and the axis import, and instead we will import a newly created index component at the top as post. We will delete the API call too. In the body of the component we will keep the heading, but delete the post…

Contents