React native 如何将redux saga与redux persist或alternative一起使用?
我想在应用程序启动时从API获取一些数据。在我的应用程序中,我坚持使用redux,现在我决定使用redux saga,但它不起作用。不过,我有一个项目的代码,实际成本至少为20万美元,所以我重复了该代码。它仍然不起作用。我认为,这个函数分派没有执行。这是我的密码。如果您不知道解决方案,请告诉我备选方案,因为截止日期:) App.tsxReact native 如何将redux saga与redux persist或alternative一起使用?,react-native,redux,react-redux,redux-saga,redux-persist,React Native,Redux,React Redux,Redux Saga,Redux Persist,我想在应用程序启动时从API获取一些数据。在我的应用程序中,我坚持使用redux,现在我决定使用redux saga,但它不起作用。不过,我有一个项目的代码,实际成本至少为20万美元,所以我重复了该代码。它仍然不起作用。我认为,这个函数分派没有执行。这是我的密码。如果您不知道解决方案,请告诉我备选方案,因为截止日期:) App.tsx const App: React.FC = () => { const {store, persistor} = configureStore();
const App: React.FC = () => {
const {store, persistor} = configureStore();
return (
<Provider store={store}>
<PersistGate persistor={persistor} loading={null}>
<Navigator />
</PersistGate>
</Provider>
);
};
mapToDispatchProps
const mapDispatchToProps = (dispatch: any) => {
return {
changeWiFiState: (state: boolean) => {
dispatch(changeWiFiState(state));
},
addToScannedCodesNoWifi: (item: string) => {
dispatch(addToScannedCodesNoWifi(item));
},
changeCart: (item: any) => {
dispatch(changeCart(item));
},
saveLocal: (item: any) => {
console.log('fsf')
dispatch({type: "SET_LOCAL_STORAGE_REQUESTED"})
}
};
};
const ScannerScreen = connect(
mapStateToProps,
mapDispatchToProps,
)(_ScannerScreen);
export {ScannerScreen}
rootSaga
export default function* rootSaga() {
takeEvery("SET_LOCAL_STORAGE_REQUESTED", saveLocal)
}
saveLocal
function* saga() {
axios.get('https://server-for-rn.herokuapp.com/code/codes').then(response => {
console.log(response.data)
return doArr(response.data)
})
}
export function* saveLocal() {
console.log('fdsfgs')
let res = call(saga)
yield put ({type: "SET_LOCAL_STORAGE", payload: res})
}
您还没有包括saveLocal saga/函数的定义,不清楚ScannerScreen何时发出所请求的
SET\u LOCAL\u STORAGE\u
操作,您还没有包括任何调试步骤。您好,我在那里添加了saveLocal函数。请检查一下!
function* saga() {
axios.get('https://server-for-rn.herokuapp.com/code/codes').then(response => {
console.log(response.data)
return doArr(response.data)
})
}
export function* saveLocal() {
console.log('fdsfgs')
let res = call(saga)
yield put ({type: "SET_LOCAL_STORAGE", payload: res})
}