更新 2:
別の更新 - 私はこの 1 つの問題に取り組んでいます。redux-form からの値がアクションに送信されますが、これにまで絞り込まれます。
export function signinUser(values) {
console.log('function about to run, email: ' values.get('email'));
}
コンソール ログ エントリも表示されません。ただし、単純なコンソール ログのみを使用した同じ機能は機能します。
export function signinUser() { console.log('実行しようとしている関数'); }
アップデート:
動作するコードと動作しないコードの唯一の違いはredux-form
とimmutablejs
です。これらを動作中のアプリに移植しようとしましたが、動作は同じです。
私は自分のフォームを送信し、redux-formvalues
を関数に送信しています。ここで、値を axios に渡すために使用values.get('email')
しています。values.get('password')
handleFormSubmit(values) {
console.log('sending to action...', values);
this.props.signinUser(values);
}
ログインフォームがあり、onSubmit
アクションをディスパッチする関数に値を渡しています。
コードはフォークしたリポジトリで機能しますが、自分のアプリに転送しています。私が抱えている問題は、関数が起動していないように見えることであり、console.log
ステートメントを追加する場所を見つけるのに苦労しています。
console.log
発火するのは2行目だけです。
export function signinUser(values) {
console.log('function will run');
return function(dispatch) {
axios.post(TOKEN_URL, {
email: "a@a.com",
password: "a",
method: 'post',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
})
.then(response => {
console.log('response: ', response.data.content.token );
// If request is good...
// - Update state to indicate user is authenticated
dispatch({ type: AUTH_USER });
// decode token for info on the user
var decoded_token_data = jwt_decode(response.data.content.token);
// - Save the JWT token
localStorage.setItem('token', response.data.content.token);
console.log(localStorage.getItem('token'));
// - redirect to the appropriate route
browserHistory.push(ROOT_URL);
})
.catch(() => {
// If request is bad...
// - Show an error to the user
dispatch(authError('Bad Login Info'));
});
}
}