I'm working on edit/update function and what I want to do is to save the response of axios.get to setState
right after I click the a specific row from the table.
const [dataSystem, setdataSystem] = useState([])
const [systemDetails, setsystemDetails] = ({
ID: '',
.....,
})
const getAllSystems = async() => {
......
}
const getDependentSystems = async() => { //this is being triggered by a handleselectedSysDep when a row selected
const response = await axios.get('/API' + ID) //ID is being passed by handleselectedSysDep from the selected row
console.log('LIST OF SYSTEM', response.data)
setdataSystem(response.data)
}
const [selectedSystemID, setselectedSysID] = useState('');
let selectedSysID;
const handleselectedSysDep = (ID, action) => { //will be triggered when a row selected
setsystemDetails(ID);
selectedSysID = {...selectedSystemID, 'ID': ID.ID}
getDependentSystems();
}
useEffect(() => {
getAllSystems ();
})
What I want is when getDependentSystems()
was called, setdataSystem
will be populated right away to display the response data of the API since I'm doing edit. Hope you can help me with this.
Here's the result of console.log('LIST OF SYSTEM', response.data)
Thank you