@use-rematch/core
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

@use-rematch/core

npm

install

pnpm i @use-rematch/core

usage

create hook in compnent without dispatch types

import { useRematch } from '@use-rematch/core';

const [state, dispatch] = useRematch({
  name: '@use-rematch/core',
  state: {
    cnt: 0,
    loading: false,
  },
  reducers: {
    add: (state, payload?: number) => {
      return {
        ...state,
        cnt: payload ? state.cnt + payload : state.cnt + 1,
      };
    },
    toggleLoading: (state) => {
      return {
        ...state,
        loading: !state.loading,
      };
    },
  },
  effects: {
    async asyncAdd(payload: number, state: State) {
      this.toggleLoading();
      setTimeout(async () => {
        this.add(payload);
        this.toggleLoading();
      }, 1000);
    },
  },
});

Package Sidebar

Install

npm i @use-rematch/core

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

24.5 kB

Total Files

12

Last publish

Collaborators

  • qidanta