Ich habe die folgende Aktion:Kann nicht Zustand aktualisiert siehe
export function loginUserRequest() {
console.log('ACTION CALLED');
return {
type: LOGIN_USER_REQUEST,
};
}
und das ist das Reduktions:
export default function loginReducer(state = initialState, action) {
switch (action.type) {
case LOGIN_USER_REQUEST:
console.log('REDUCER CALLED');
return Object.assign({}, state, {
isAuthenticated: true,
isAuthenticating: true,
statusText: null,
});
default:
return initialState;
}
}
Dann meine Komponente:
class Login extends React.Component {
goHome =() => {
browserHistory.push('/');
}
handleSubmit = (values) => {
console.log(this.props.isAuthenticating);
this.props.actions.loginUserRequest();
console.log(this.props.isAuthenticating);
}
render() {
return (
<LoginForm onSubmit={this.handleSubmit} />
);
}
}
Login.propTypes = {
actions: PropTypes.objectOf(PropTypes.func).isRequired,
isAuthenticating: PropTypes.bool.isRequired,
};
const mapStateToProps = state => ({
token: state.login.token,
isAuthenticated: state.login.isAuthenticated,
isAuthenticating: state.login.isAuthenticating,
});
const mapDispatchToProps = dispatch => ({
actions: bindActionCreators(actionCreators, dispatch),
});
export default connect(mapStateToProps, mapDispatchToProps)(Login);
LoginForm
ist ein redux-form
Komponente.
die expeted ouput aus der handleSubmit
Funktion ist also:
false
ACTION CALLED
REDUCER CALLED
true
aber es gibt mir:
false
ACTION CALLED
REDUCER CALLED
false
Aber im redux dev tool
kann ich das diff in LOGIN_USER_REQUEST
sehen:
Warum sehe ich es nicht innerhalb der handleSubmit
Funktion? Ist es etwas mit redux-form
Bibliothek verbunden?
Zusätzliche Informationen:
Added shouldComponentUpdate
und logger
shouldComponentUpdate = (nextProps, nextState) => {
console.log('Should component update called');
if (this.props.isAuthenticating !== nextProps.isAuthenticating) {
console.log('distntict');
return true;
}
console.log('false');
return false;
}
Versuchen hilft 'shouldComponentUpdate' Methode in Ihrer Komponente hinzufügen, und true zurück, wenn die Requisiten waren nicht gleich. –
@DmitriyKovalenko Blick auf meinen aktualisierten Beitrag. Ich habe auch einen Logger hinzugefügt – FacundoGFlores
Nur eine weitere Variante, die ich mir vorstellen kann, ist, dass Sie Ihre Komponente nicht über redux 'connect' verbinden und nicht' mapStateToProps' erstellen, aber es scheint, dass Sie das tun. –