Skip to content
Advertisement

How to load/populate an existing database record to a ReactJs form

I got this form where you can update user data (code, article, price, vat, status, companyid).

I would like to populate the Update/Edit form with user data so i can easly modify them (once this form shows up, i would like to get data from API in each input and show them as input value).

JavaScript

src/Service/api.js:

JavaScript

Advertisement

Answer

Create a new function that handle loading of data then created a useEffect function and put inside the handled function so the data will be loaded in inputs (populated):

JavaScript

And in inputs, change each defaultValue to:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement