像 Vue 一样写 React

$ npm install zenbox
开始使用
counter.tsx
import { createStore, useComputed, useStore, useWatch } from "zenbox";  

// 自动推导类型
const store = createStore({
  count: 1,
  addStar: () => store.setState(state => { state.count++; }),
});

function StarRating() {
  const { count, addStar } = useStore(store);

  // 计算属性
  const score = useComputed(() => store.value.count * 2);

  // 监听变化
  useWatch(() => store.value.count, count => {
    if (count === 3) alert('Already 3 stars!');
  });

  return (
    <div onClick={addStar}>
      <p>{'⭐️'.repeat(count)}</p>
      <p>Score: {score}</p>
    </div>
  );
}
ZenBox