next.js/examples/with-rematch/shared/models/counter.js
counter.js23 lines592 B
import { createModel } from "@rematch/core";

const counter = createModel({
  state: 0, // initial state
  reducers: {
    // handle state changes with pure functions
    increment: (state, payload) => {
      if (typeof payload === "object") return state + 1;
      return state + payload;
    },
  },
  effects: {
    // handle state changes with impure functions.
    // use async/await for async actions
    async incrementAsync(payload, rootState) {
      await new Promise((resolve) => setTimeout(resolve, 1000));
      this.increment(payload);
    },
  },
});

export default counter;
Quest for Codev2.0.0
/
SIGN IN