0
문제는 상태가 정의되지 않은 상태입니다. nextProps.userid의 첫 x 째 콘솔 로그는 올 Y 른 사용자 ID를 표시하지만 상태는 변경되지 않으며 두 x 째 콘솔 로그는 다시 널입니다.반응 소품이 상태를 업데이트하지 않음
class Profile extends React.Component {
constructor(props) {
super(props);
this.state = {
user: this.props.userid,
};
}
componentWillReceiveProps(nextProps){
console.log('PROFILE USERID', nextProps.userid)
const userid = nextProps.userid
this.setState({user:userid})
console.log('PROFILE USERID 2', this.state.user)
}