私は1回呼び出されるredux-sagaを持っていますが、2回実行しています。redux-sagaが2回注入される
これは、佐賀を開始アクションです:
export function createRequest (data) {
return {
type: CREATE_REQUEST,
payload: {data}
};
}
と私のsagas.jsファイルがこのようになります。
export function* create (x) {
try {
const response = yield call(request, URL_TO_API, Object.assign({}, buildBaseHeaders('en'), {
method: 'post',
body: JSON.stringify(x.payload.data)
}));
yield put(createSuccess(response));
} catch (error) {
yield put(createFailure(error));
}
}
... my other sagas
export default function* defaultSaga() {
yield takeLatest(CREATE_REQUEST, create);
... my other calls
}
私はリアクトコンポーネントにサガを注入してる方法ですこれは:
const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withReducer = injectReducer({key: 'myComponent', reducer});
const withSaga = injectSaga({key: 'myComponent', saga});
export default compose(withReducer, withSaga, withConnect) MyComponent;
しかし、サガは2回注入されます。では、私はここで何が欠けていますか? MyComponentがレンダリングされる回数に関係なく、一度しかサガを挿入することはできませんか?
誰がcreateSagaを呼び出しますか?それが2回実行され、1つが失敗した場合は、create関数を1回だけconsole'ingすることはOKです。私はここに全体の画像がありません:/ – Lucio
'create'は' createRequest'アクションによって呼び出されます。そのアクションは1回使用されますが、サガは2回呼び出されます。 – assembler
ああ、今私はアイデアがありません:( – Lucio