한 번 호출되는 redux-saga가 있지만 두 번 실행됩니다. redux-saga를 두 번 주입했습니다.
이
은 사가 시작하는 작업입니다 :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;
그러나 사가가 두 번 주입됩니다. 그럼 내가 뭘 놓치고 있니? MyComponent가 렌더링되는 횟수와 상관없이 무용담을 한 번만 주입하려면 어떻게해야합니까?
누가 createSaga를 호출합니까? 두 번 실행되고 하나가 실패하면 create 기능을 한 번만 console'ing하는 것이 좋습니다. 나는 여기에 전체 그림을 놓치고있다./ – Lucio
'create' 무언가는'createRequest' 액션을 통해 호출됩니다. 이 동작은 한 번 사용되지만 무용담은 두 번 호출됩니다. – assembler
오, 이제 아이디어가 부족합니다. ( – Lucio