Skip to content

Commit c9dcaa7

Browse files
committed
exported type ReactVariableHook, modified documentation
1 parent 21c5bba commit c9dcaa7

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
# shared-react-variables
1+
# <p align="center">Shared React variables</p>
22

3-
Easy and comfortable React state manager.
3+
Easy and comfortable React mutable state manager 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 variables in your application.
44

5-
## API
5+
## <p align="center">1. Exported types</p>
66

7-
### **createUseSharedVariable**
8-
Takes initial state as a parameter. Returns a hook can be imported and used anywhere in your application. When you use this hook, it returns you mutable global state. Whenever this state is changed component will be rerendered (this behaviour can be changed via *rerenderOnChange* flag).
7+
```ts
8+
type ReactVariableHook<T> = (rerenderOnChange?: boolean) => T;
9+
```
10+
11+
## <p align="center">2. API</p>
12+
13+
### <p align="center">createUseSharedVariable</p>
14+
#### **Description**
15+
Takes initial state as a parameter. Returns a hook can be imported and used anywhere in your application. When you use this hook, it returns you mutable global state. Whenever this state is changed component will be rerendered (this behaviour can be changed via *rerenderOnChange* flag in the hook).
916

10-
#### Signature
17+
#### **Signature**
1118
```ts
12-
function createUseSharedVariable<T extends object>(initialState: T): (rerenderOnChange?: boolean) => T
19+
<T extends object>(initialState: T) => ReactVariableHook<T>;
1320
```
1421

15-
#### Usage example
22+
#### **Usage example**
1623
```ts
1724
// feel free to use this state hook anywhere!
1825
const useTimer = createUseSharedVariable({ ticks: 0 });
1926

2027
export { useTimer }
2128
```
2229

23-
## Example
30+
## <p align="center">3. Package usage example</p>
2431

2532
https://codesandbox.io/s/react-shared-variables-example-f7feo7

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.0",
3+
"version": "1.0.1",
44
"description": "Easy and comfortable React state manager",
55
"main": "transpiled/index.js",
66
"scripts": {

sources/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { deepProxy } from "@alevnyacow/deep-js-proxy";
44
import { useRerenderer } from "./use-rerenderer";
55
import { rerenderersList } from "./rerenderers-list";
66

7-
function createUseSharedVariable<T extends object>(initialState: T) {
7+
type ReactVariableHook<T> = (rerenderOnChange?: boolean) => T;
8+
9+
function createUseSharedVariable<T extends object>(
10+
initialState: T
11+
): ReactVariableHook<T> {
812
const variableIdentifier = v4();
913
const sharedVariable = deepProxy(
1014
[rerenderersList.fire],
@@ -35,4 +39,4 @@ function createUseSharedVariable<T extends object>(initialState: T) {
3539
return useSharedVariable;
3640
}
3741

38-
export { createUseSharedVariable };
42+
export { createUseSharedVariable, ReactVariableHook };

0 commit comments

Comments
 (0)