асинхронных запросов
redux-saga
saga работает с useRedcuer ом не?
да
аха. спосибо
function* incrementAsync() { const previousState = yield select(); yield call(console.log, "I AM STARTING TO INCREMENT FROM", previousState); yield delay(2000); yield put({ type: "INCREMENT" }); const state = yield select(); yield call(console.log, "I AM FINISHED INCREMENTING TO", state); } function* saga() { yield takeLatest("INCREMENT_ASYNC", incrementAsync); } export const Example = () => { const [state, dispatch] = React.useReducer((state, action) => { switch (action.type) { case "INCREMENT": return state + 1; default: return state; } }, 0); const put = useReactSaga({ state, dispatch, saga }); return ( <div> <p>Clicked {state} times!</p> <button onClick={() => put({ type: "INCREMENT_ASYNC" })}> increment async </button> </div> ); };
отдуший!
Обсуждают сегодня