Adding the edit functionality
We will implement the edit functionality by adding the Edit button to each table row. When the row Edit button is pressed, it opens a modal form where the user can edit the existing car and save their changes. The idea is that we pass car data from the grid row to the edit form, and the form fields are populated when the form is opened:
- First, create a file called
EditCar.tsxin thecomponentsfolder. We have to define aFormPropstype for our props, and this can be defined inside our component because we don’t need this type anywhere else. The type of data that will be passed to theEditCarcomponent is theCarResponsetype. We will also create a state for car data like we did in the add functionality section. The code for theEditCar.tsxfile looks like the following:// EditCar.tsx import { useState } from 'react'; import { Car, CarResponse } from '../types'; type FormProps = { cardata: CarResponse; ...