项目作者: ShanaMaid

项目描述 :
React hook for MobX and Mobx React!
高级语言: TypeScript
项目地址: git://github.com/ShanaMaid/react-use-mobx.git
创建时间: 2019-08-27T06:30:56Z
项目社区:https://github.com/ShanaMaid/react-use-mobx

开源协议:MIT License

下载


React Use Mobx version minzipped size downloads

useObservable is a React Hook that help you use mobx and mobx-react.

useObservable use help update data automatically insteadof setState!

Install

  • npm install mobx mobx-react react-use-mobx or
  • yarn add mobx mobx-react react-use-mobx

Example

Online Demo

  1. import React, { useState } from 'react';
  2. import { useObservable, observer } from 'react-use-mobx';
  3. import { render } from 'react-dom';
  4. const App = observer(() => {
  5. const [ count1, setCount ] = useState({a: 1});
  6. /**
  7. * initialState must be Object!!!!!!
  8. */
  9. const count2 = useObservable({a: 1});
  10. return (
  11. <div>
  12. <h2>useState</h2>
  13. <button onClick={() => setCount({a: count1.a + 1})}>count: {count1.a}</button>
  14. <h2>react-use-mobx</h2>
  15. <button onClick={() => count2.a++}>count: {count2.a}</button>
  16. </div>
  17. );
  18. });
  19. render(<App ></App>, document.getElementById('root'));