On form submit I am calling an API and I am getting a response from API. I want to use that response value in other places. When I debug I can see value in response but while assigning it using useState it is always null which is the default value at first.
const[matterID, setMatterID]= useState(null);
const[matterName, setMatterName]= useState(null);
const submitHandler= async (e)=>{
e.preventDefault();
setPosting(true);
axios.post(constants.MATTER_SAVE_URI, {matterModel:matterDetail, prefix:matterDetail.Prefix, suffix:matterDetail.Suffix}, {
headers: {
'Content-Type': 'application/json'
}})
.then((response) => {
setMatterID(prev =>{
return{...prev, ...response.data.responseData.matterNumberLTB }
})
console.log("matteri",matterID);
setMatterName(response.data.responseData.name);
//i also tried using this way.
axios.post(constants.ADD_MEMBER_TO_GROUP + "/" + matterID, {
headers: {
'Content-Type': 'application/json'
}})
.then((response) => {
axios.post(constants.ACCESS_ALL_MEMBER_MATTER + "/" + matterID + "/" + hasAccess, {
headers: {
'Content-Type': 'application/json'
}})
}