You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.1 KiB

2 years ago
  1. // 导入中间件,连接mobx、react,完成响应式变化
  2. import { observer } from 'mobx-react-lite'
  3. import { useStore } from './store/index'
  4. function App() {
  5. // 注意:解构赋值到 store 实例对象就可以了,防止破坏响应式,用哪个 store 就解构那个 store
  6. const { counterStore } = useStore()
  7. return (
  8. <div className="App">
  9. {/* list = [1, 2, 3, 4, 5, 6] 是引用型数据类型,值存放在堆内存中,在栈内存存放的是一个地址,这个地址将会指向堆内存中引用数据类型的具体数值 */}
  10. {counterStore.list.map((item) => {
  11. return <div key={item}>{item}</div>;
  12. })}
  13. <br />
  14. <button onClick={() => {
  15. counterStore.addList();
  16. console.log(counterStore.list);
  17. }
  18. }>+</button>
  19. <br />
  20. {/* {counterStore.count}
  21. <br/>
  22. <button onClick={counterStore.addCount}>+</button> */}
  23. </div>
  24. )
  25. }
  26. export default observer(App)