Skip to content

Instantly share code, notes, and snippets.

@ctrlplusb
Created November 5, 2018 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrlplusb/b61b4caa870531a5ed85bc0f05384407 to your computer and use it in GitHub Desktop.
Save ctrlplusb/b61b4caa870531a5ed85bc0f05384407 to your computer and use it in GitHub Desktop.
import { createStore, effect } from 'easy-peasy'; // 👈 import the helper
const store = createStore({
session: {
user: undefined,
// 👇 define your effectful action
login: effect(async (dispatch, payload, getState) => {
const user = await loginService(payload)
dispatch.session.loginSucceeded(user)
}),
loginSucceeded: (state, payload) => {
state.user = payload
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment