프로젝트
GitHub에서 보기
awmleer/reto
소개
Flexible and efficient React Store with hooks.
웹 및 앱 개발What you can do
- 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.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalReto
___ __
/ _ \___ ___ _____/ /_
/ , _/ -_) / _ `/ __/ __/
____ /_/|_|\__/ \_,_/\__/\__/
/ __/ / /____ _______
_\ \ / __/ _ \ / __/ -_)
/___/ \__/\___/ /_/ \__/
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
Install
$ yarn add reto
# or
$ npm install reto --save
Try It Online
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.
관련 프로젝트 살펴보기
불러오는 중…