Display the Task List
Next, we’ll use the tasks from the backend and display them in the frontend. We’ve prepared a Todo
React component that displays an array of Task
. Note that we’re using the same “shared” Task
type that we previously used in the backend.
Let’s add the following code to display the tasks:
Code Explanation
- We ask Remult for a
Repository
of typeTask
and store it intaskRepo
. The repository is used to perform all CRUD operations for our tasks. - Previously, we used a Repository in the
initApi
on the backend to create rows directly in our database. Now, we use the same Repository abstraction on the frontend. When it runs in the frontend, the same methods will perform REST API calls to the backend to get and manipulate the data. - We use the
find
method of the repository in theuseEffect
hook to get the tasks from the backend and set them in the state.
This code makes a REST API call to the backend at the /api/tasks
URL to get the tasks and display them.
You can see the tasks in the preview window below.
Files
Preparing Environment
- Installing dependencies
- Starting http server