0.9.3 • Published 3 years ago

reto v0.9.3

Weekly downloads
40
License
MIT
Repository
github
Last release
3 years ago

Reto

GitHub codecov npm version npm downloads npm bundle size (minified) Build Status codacy Vulnerabilities React

             ___                  __ 
            / _ \___    ___ _____/ /_
           / , _/ -_)  / _ `/ __/ __/
   ____   /_/|_|\__/   \_,_/\__/\__/ 
  / __/  / /____     _______         
 _\ \   / __/ _ \   / __/ -_)        
/___/   \__/\___/  /_/  \__/         
                                     

Flexible and efficient React Store with hooks.

Features

  • Supports all react hooks. Writing a store is just like writing a component.
  • Simple but efficient, quite easy to learn.
  • Use multiple stores to organize your data.
  • Dependency injection based on React Context.
  • Strongly typed with Typescript, also works well with JS.

Docs

English | 中文

Install

$ yarn add reto
# or
$ npm install reto --save

Try It Online

Edit react

A Simple Example

Every Store is a function similar to a custom hook. In the body of a Store function, you can use any react hooks, for example, useState, useEffect, useRef.

export function FooStore() {
  const [x, setX] = useState(initial)
  return {
    x,
    setX
  }
}

Then, you can provide a store "instance" using Provider component.

import {Provider} from 'reto'

<Provider of={FooStore}>
  <App/>
</Provider>

By using the useStore hook, you can retrieve the store "instance" in components, and subscribe to its changes.

import {useStore} from 'reto'

const App: FC = (props) => {
  const fooStore = useStore(FooStore)
  
  function changeStore() {
    fooStore.setX(fooStore.x + 1)
  }
  return (
    <div>
      <button onClick={changeStore}>Change</button>
      {fooStore.x}
    </div>
  )
}

So when you click the "Change" button, the setX function of fooStore is executed, thereby triggers the update of state x and the rerender of App component. Everything is simple and straightforward.

0.9.3

3 years ago

0.9.3-alpha.0

3 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.3

4 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.3

5 years ago

0.4.1

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago