If the attribute value of state in React is this.props.xx, it will be undefined.

for example, write code like this in a class component, state= {currentPic:this.props.pic}; pic is data passed in through connect (mapStateToProps), why is the value of each property of props in the constructor undefined? The function below the constructor uses this.props.xx but can access the value

Jun.01,2022

you passed the redux, you write the values in the reducer as fixed to see if you can get it, just check up a little bit


No props? Normally, you can get it

constructor(props) {
        super(props);
        this.state = {
            popover: false,
            Data:2,
            displayQrCode: false,
            imgBase64: '',
        };
    }
The value of props cannot be taken in

state because constructor is the first part of the component to execute. If the value of the property of state is this.props.xx, then it will be undefined (https://codeshelper.com/q/10...)

.
Menu