Skip to content

Commit 85eed00

Browse files
authored
Update README.md
1 parent 3044d16 commit 85eed00

1 file changed

Lines changed: 23 additions & 27 deletions

File tree

README.md

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
# useRestate
22

3-
A React hook that subscribes your state selector to the store.
4-
3+
A React Hook that subscribes your state selector to the store and memoizes your action dispatchers.
4+
5+
```js
6+
function Count() {
7+
const increment = useAction({ type: 'INCREMENT' });
8+
const { count } = useRestate(state => {
9+
return { count: state.count };
10+
});
11+
12+
return (
13+
<div>
14+
<h2>{count}</h2>
15+
<button onClick={increment}>Increment</button>
16+
</div>
17+
);
18+
}
19+
```
20+
521
## Install
622

723
```bash
@@ -20,47 +36,27 @@ npm install use-restate
2036
- Works with any Redux-like store
2137
- Memoized action dispatch functions
2238
- Quick access to store dispatch
23-
- Typescript support
39+
- Full Typescript support
2440

2541

2642
## Prerequisites
2743

28-
React hooks require react & react-dom at version 16.7.0-alpha.0 or higher.
44+
⚠️ React hooks require `react` & `react-dom` at version 16.7.0-alpha.0 or higher.
2945

3046
## Usage
3147

32-
`use-restate` requires you to provide your Redux-like store to `RestateProvider`.
48+
The `use-restate` package requires you to provide your Redux-like store to `RestateProvider`.
3349

3450
### Setting up the store
3551

36-
Before using the hook, your store should be passed to `RestateProvider`.
52+
Before using the hook, your store should be passed to `RestateProvider`. You also have access to `RestateContext` should you need it to inject middleware.
3753

3854
```js
3955
import React from 'react';
4056
import { createStore } from 'redux';
4157
import { RestateProvider, RestateContext } from 'use-restate';
4258

43-
const Actions = {
44-
INCREMENT: 'INCREMENT',
45-
DECREMENT: 'DECREMENT',
46-
};
47-
48-
const Reducer = (state: { count: number }, action: any) => {
49-
switch (action.type) {
50-
case Actions.INCREMENT:
51-
return {
52-
count: state.count + 1,
53-
};
54-
case Actions.DECREMENT:
55-
return {
56-
count: state.count - 1,
57-
};
58-
default:
59-
return state;
60-
}
61-
};
62-
63-
const store = createStore(Reducer, { count: 3 });
59+
...
6460

6561
export default function App() {
6662
return (

0 commit comments

Comments
 (0)