0.0.3 • Published 4 years ago

@lowinc/quellingblade v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

QuellingBlade

堕落地精的斧头,能让你更快的在森林中穿行。

State & Handler

import blade, {useBlade} from "./src";
import {useReducer} from "react";

const initState = {
  name: "lowinc",
  age: 100,
};

type State = typeof initState;

const handler = {
  updateName(state, payload: State["name"]) {
    return {
      ...state,
      name: payload,
    };
  },
};

Pages

通过blade创建简便的mutations和reducer

const {mutations, reducer} = blade(handler);

export default function PageInBlade() {
  const [state, dispatch] = useReducer(reducer, initState);

  const updateName = () => {
    dispatch(mutations.updateName("LAO_SI_JI"));
  };

  return <button onClick={updateName}>{state.name}</button>;
}

或者直接使用useBlade代替useReducer

export default  function PageInUseBlade() {
  const {state, blade} = useBlade(handler, initState);

  const updateName = () => {
    blade.updateName("LAO_SI_JI");
  };

  return <button onClick={updateName}>{state.name}</button>;
}
0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago