Skip to content

Commit 1da55ad

Browse files
authored
Merge pull request #14 from alevnyacow/feature/example-in-docs
added example in about section
2 parents 659b6de + 84aca68 commit 1da55ad

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,32 @@
99

1010
## **About**
1111

12-
Shared React variables provide you easy and comfortable mutable state management based on hooks. It's extremely simple - you generate a hook in one line and then you can use it anywhere to operate with your state! Also you can have any number of such state variables in your application.
12+
Shared React variables provide you easy and comfortable mutable state management based on hooks. It's extremely simple - you generate a hook in one line and then you can use it anywhere to operate with your state! Also you can have any number of such state variables in your application.
13+
14+
```tsx
15+
// creating timer state hook
16+
const useTimer = createUseSharedVariable({ ticks: 0 });
17+
18+
const Timer = () => {
19+
// using timer state
20+
const timer = useTimer();
21+
useEffect(() => {
22+
setInterval(() => {
23+
// state is mutable
24+
timer.ticks++;
25+
}, 1000);
26+
}, []);
27+
28+
return <div>{timer.ticks}</div>
29+
};
30+
31+
const AnotherTimerWithSameState = () => {
32+
// using same timer state in another component
33+
const timer = useTimer();
34+
35+
return <div>{timer.ticks}</div>
36+
};
37+
```
1338

1439
## 🔍 **Exported types**
1540

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alevnyacow/shared-react-variables",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Easy and comfortable React state manager",
55
"main": "transpiled/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)