Answer the question
In order to leave comments, you need to log in
How to update the data in the form if the state is overwritten?
componentDidMount() {
this.fetch();
}
fetch = () => {
this.fetchPermissions();
};
fetchPermissions = () => {
return api
.get(`api/test/get`)
.then(response => {
this.setState({
userData: response.data
});
})
.catch(e => {
this.setState({
userData: []
});
});
}
render() {
const {
iconLoading,
permissions,
userData
} = this.state;
console.log(userData)
return ( <>
<Form>
<Col xs = {24}
xl = {12}
className = "__border-right streams_partner_trackers" >
{
this.validator(
'name',
t('user_name'), <
Input placeholder = {
t('enter_user_name')
}
size = "large"
value = {
userData.user.name
}
/>, [{
required: true,
message: t('message.field_is_required')
}])
} </Form> </>
)
}
Answer the question
In order to leave comments, you need to log in
Do a ternary check directly on value
value = {
userData.user.name ? userData.user.name : "Loading..."
}
userData.user.name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question