redux saga selectors, how do I access state from a saga?
You will have to use selectors for that. I'll give a simple example. Create a file selectors.js
and add the fields you want to select from your store, as shown below.
export const username = (state) => state.user.name;
Then in your saga, import the selectors as,
import * as selectors from './selectors';
and when you require username
in your saga, you can simply do,
import {select} from 'redux-saga/effects';......function *sampleSaga(params) { const username = yield select(selectors.username);}
the constant username
in sampleSaga
will now hold the username value from state.
Looks like things may have changed a little. Not sure, the redux-saga docs did not help me out. Could be the way my store is set up. But if you're stuck in 2021, this may help:
I have a state with the property 'currentUser', which in turn has property 'id'. I need the id.
const getUser = (state) => state.get('currentUser')function* addItem() { const currentUser = yield select(getUser) const id = currentUser.get('id') debugger}function* itemQuantitySaga() { yield all([takeLatest(INCREASE_ITEM_QUANTITY, addItem)])}