Blog>
Snippets

State Update with put Effect

Illustrates updating the Redux store state by dispatching an action with the `put` effect after an asynchronous operation completes.
import { put } from 'redux-saga/effects';

// Define an action
const userLoggedIn = (user) => ({
  type: 'USER_LOGGED_IN',
  payload: user
});
Defines a Redux action for when a user has logged in. This action will be dispatched to update the Redux store state.
function* handleLoginSuccess(user) {
  // Dispatch the userLoggedIn action to update the store
  yield put(userLoggedIn(user));
}
A generator function that takes a user object as an argument and yields the put effect, which dispatches the userLoggedIn action to the Redux store. This is typically called after an asynchronous login operation succeeds.