Object.values()
can convert null
or undefined
to an object with properties it can extract.
Before the API returns, the mapStateToProps
selector tries to get the values of state.profile
, which is undefined
:
const mapStateToProps = state => {
return { profile: Object.values(state.profile) };
};
Set the initial value of the profile
as an empty object:
const initialState = {
values: {
profile: {}
}
};
Rr use a fallback value - {}
at the selector's level:
return { profile: Object.values(state.profile ?? {}) };
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…