import React, { useState, useCallback } from 'react'; import { Card, Button, Input } from 'antd'; import { Provider, useStore } from '../../src/store'; import { store, mutations, Store } from './store'; import './index.css'; import 'antd/dist/antd.css'; function Count() { const countState = useStore((store: Store) => { const { state, computed } = store; const { count } = state; const { plusOne, plusTwo } = computed; return { count, plusOne, plusTwo, }; }); mutations.log('计数器组件重新渲染💐'); return ( 计数器 store中的count现在是 {countState.count} computed值中的plusOne现在是 {countState.plusOne.value} 嵌套computed值中的plusTwo现在是 {countState.plusTwo.value} add ); } function Chat() { const message = useStore((store: Store) => store.state.message); const [value, setValue] = useState(''); mutations.log('聊天室组件重新渲染💐'); const onSubmit = (e: React.FormEvent) => { e.preventDefault(); mutations.chat(value); }; return ( 聊天室 当前消息是: {message} setValue(e.target.value)} placeholder="请输入消息" /> ); } function Logger() { const logs = useStore((store: Store) => { return store.state.logs.map((log, idx) => ( {log} )); }); return ( 控制台 {logs} ); } export default () => { return ( ); };
{log}