This is my react jsx file code overview
const [name, setName] = useState("");
// and the prefield data which I want to be prefield is commit from API which is
const nameFromApi = userDatails?.name;
// Here is my function return JSX
<input defaultValue={nameFromApi} value={name} onChange={e => setName(e.target.value)} />
You can initialize name with the value so that will be the initial value of the input
const [name, setName] = useState(userDatails?.name);
<input value={name} onChange={e => setName(e.target.value)} />
If I understand correctly, you are getting a respone from api which is userDatails and you want your input to have the value if userDatails as its initial value?
You can do something like this
const [name, setName] = useState("");
useEffect(()=>{
//call your api and get value
...
setName(userDatails?.name)
},[])