아래 코드를 가지고 있지만 내 상태가 업데이트되지 않습니다. 사용자가 올바른지 여부를 확인하기 위해 Angular http ajax-call을 사용하고 있습니다. 새 오류 메시지를 받침대로 전달하면 아무 일도 일어나지 않지만 구성 요소는 nextProps
을 통해 액세스 할 수 있기 때문에 메시지를받습니다. 반응 상태/소품이 업데이트되지 않습니다
constructor
,
componentWillReceiveProps
및
shouldComponentUpdate
그냥
{ this.props.error }
을 렌더링로 이동하려고했지만, 그 중 하나가 작동하지 않았다.
이 내 DOM을 처음
// Some code
.then(function(response){
// Some code
}, function(response){
_this.renderLogin("User not found"); // Is sending the error-message to the function
});
// Some code
_this.renderLogin = function(error){
render(
<Login error={error} />,
document.getElementById("app")
);
};
_this.renderLogin("Standard");
이 로그인 구성 요소입니다 렌더링하는 기능을 렌더링 : 사전에 어떤 도움
이class Login extends React.Component {
constructor(props){
super(props);
this.state = {
error: this.props.error
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.error !== this.state.error) {
this.setState({ error: nextProps.error });
console.log(nextProps.error); // User not found
console.log(this.state.error); // Standard
}else{}
}
shouldComponentUpdate(nextProps, nextState){
console.log(nextState.error); // User not found
console.log(nextProps.error); // User not found
console.log(this.state.error); // Standard
return true;
}
render(){
return(
<div>
{ this.state.error } // Always showing: 'Standard'
</div>
);
}
}
export default Login;
감사를!
감사합니다. 말된다 :) – Gjermund