put() is a Redux-Saga effect that allows a saga to create (dispatch) an action to the Redux store. It's used when you want your saga to trigger a reducer or another saga that listens for specific actions.
Syntax:
import { put } from 'redux-saga/effects';
yield put({ type: 'ACTION_TYPE', payload: data });
How it helps in dispatching actions:
Triggers reducers:
After performing async logic (e.g., an API call), you can use put() to send an action that updates the Redux state.
yield put({ type: 'FETCH_SUCCESS', payload: response.data });
Flows like dispatch():
It's Saga’s way of saying dispatch(action). It does not immediately dispatch; instead, Redux-Saga interprets this effect and performs the dispatch for you.
Enables clean separation:
Keeps side effects (like API calls) inside sagas, and leaves reducers purely responsible for state updates.
Chaining logic:
You can sequence actions based on conditions or results from other effects.