У меня есть обещание в реквизитах: this.props.getProfile()
, и я хочу установить значение ответа в обещании в состояние до render ()
Я пробовал с UNSAFE_componentWillMount
и getDerivedStateFromProps
, но он всегда отвечает на обещание ожидает рассмотрения.
Вот моя попытка с UNSAFE_componentWillMount
:
UNSAFE_componentWillMount(){
this.setState({profile: this.getProfile()})
}
getProfile=()=>{
return this.props.getProfile()
.then(res =>{
if (res.type === 'ERROR_MESSAGE') {
return null;
}
return res.payload
});
}
Вот моя попытка с getDerivedStateFromProps
:
static getDerivedStateFromProps (props, state){
let a = props.getProfile()
.then(res =>{
if (res.type === 'ERROR_MESSAGE') {
return null;
}
return res.payload
});
console.log(a);
if(a.profile !== state.profile)
return {profile: a};
}