在控制台什么都没有,哪里可能是一个错误?需要得到this.props.about并检查是否为空。
reducer.js
export default function details(state = initialState, action) {
switch(action.type) {
case DETAILS_SUCCESS:
return { ...state, details: action.payload, error: '' };...
Container.js
class HeaderContainer extends Component {
render() {
const { details } = this.props, { deTails } = this.props.HeaderAction;
return <div><Header deTails={deTails} about={details.details} error={details.error} /></div>
}
}
function mapStateToProps(state) {
return {
details: state.details,
}
}
function mapDispatchToProps(dispatch) {
return {
HeaderAction: bindActionCreators(HeaderAction, dispatch),
}
}
export default connect(mapStateToProps, mapDispatchToProps)(HeaderContainer);
Component.js
componentDidMount() {
console.log(this.props.about);
}
您将不会像componentDidMount中的props那样收到更新状态,而是可以使用:
componentWillReceiveProps(nextProps){ // this is UN_SAFE
}
要么
static getDerivedStateFromProps(nextProps, prevState) { // this is recommended
}