• Stars
    star
    215
  • Rank 183,925 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flexible and efficient React Store with hooks.

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.

More Repositories

1

use-async-memo

React hook for generating async memoized data.
TypeScript
143
star
2

with-wrapper

React HOC for wrapper components.
JavaScript
35
star
3

gitmug

The GitHub app for minimalists.
TypeScript
34
star
4

morph

Turn your Markdown documents into slides.
CSS
28
star
5

zju-library

浙大图书馆app
TypeScript
19
star
6

staged-components

Make React function component staged.
TypeScript
18
star
7

use-action

Almost same to useEffect, but not deferred.
TypeScript
15
star
8

akar-icons-web-components

Akar icons as web components.
TypeScript
11
star
9

jorum

Model layer with rx.js for React applications.
TypeScript
9
star
10

dinosaur

This is the final project for "Logic and Computer Design Fundamentals".
Verilog
6
star
11

zju-ads-project

TeX
5
star
12

neuron

An open-source English words learning app.
TypeScript
5
star
13

zju-cv-exp

ZJU computer vision course experiment
C++
5
star
14

nanosql

A simple SQL Database implementation for "Database System Concepts" course.
CSS
4
star
15

zjuwlan

Command line tool for authenticating to ZJUWLAN.
JavaScript
3
star
16

konjac

Internationalization made easy.
JavaScript
3
star
17

grade-management

Final project for OOP course.
C++
3
star
18

scummer

A Python dict validator.
Python
2
star
19

zju-course-scene-change-detection

ZJU course experiment.
C++
2
star
20

zju-course-online-exam

软件工程课程在线测试系统的前端部分
JavaScript
2
star
21

zju-compilation-principle

编译原理课程的实验
Yacc
2
star
22

todo-app-with-hox

Todo App with hox.
JavaScript
2
star
23

use-creation

Replacement for useMemo with semantic guarantee. Useful for avoid expensive constant creation.
TypeScript
2
star
24

rescoped

Scoped styles made easy.
TypeScript
2
star
25

dotfiles

Shell
1
star
26

alfred-dock

An Alfred workflow to help you change dock orientation.
1
star
27

cowrite

ZJU Java course project. A very simple JavaFx application for multiple users writing together.
Java
1
star
28

joey

Using Arduino to display some of the computer's status.
Python
1
star
29

reto-demo

Created with StackBlitz ⚡️
JavaScript
1
star
30

zju-course-fake-taobao

浙江大学数字媒体设计课程作业:仿制淘宝主页
TypeScript
1
star
31

kay

Use global shortcut to switch among apps on macOS.
Swift
1
star
32

RUOK

HackxFDU project.
TypeScript
1
star
33

vis-sms-spam

信息可视化课程大作业:垃圾短信分析
Jupyter Notebook
1
star
34

automator-applets

The set of macOS automator applets that I use everyday.
1
star
35

oh-my-name

TypeScript
1
star
36

days

TypeScript
1
star
37

murder-mystery-frontend

Murder mystery game app
TypeScript
1
star
38

ssaw

四时
TypeScript
1
star
39

neuron-backend

Python
1
star
40

awmleer

1
star
41

massmail

JavaScript
1
star
42

flip-clock

CSS
1
star
43

react-use-changing

React useChanging hook.
TypeScript
1
star
44

iphone-wallpapers

My iPhone wallpapers collection (suitable for 6&6s&7&7s).
1
star
45

colorish

HTML
1
star
46

nimble

CSS
1
star
47

react-ts-starter

JavaScript
1
star
48

sparkbition

任务板系统(曾经造过的轮子之一
HTML
1
star