Skip to content

Commit 386ea5d

Browse files
committed
doc(#15): Updated README
1 parent ea23d07 commit 386ea5d

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

.changeset/eight-shrimps-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@backhooks/core": patch
3+
---
4+
5+
Updated README with new resetGlobalContext function

packages/core/README.md

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,54 @@ npm install @backhooks/core
1414

1515
This allows you to create a hook. Example of creating a simple hook:
1616

17-
````ts
17+
```ts
1818
const [useCount, configureCountHook] = createHook({
19-
data () {
19+
data() {
2020
return {
21-
count: 0
22-
}
21+
count: 0,
22+
};
23+
},
24+
execute(state) {
25+
state.count++;
26+
return state.count;
2327
},
24-
execute (state) {
25-
state.count++
26-
return state.count
27-
}
28-
})
28+
});
29+
```
2930

3031
`runHookContext: <T>(fn: () => T): Promise<T>`
3132

3233
This allows you to run a hook context. Any hook called within the `runHookContext` callback will have a specific state attached to it:
3334

3435
```ts
3536
runHookContext(() => {
36-
console.log(useCount()) // 1
37-
console.log(useCount()) // 2
38-
console.log(useCount()) // 3
39-
})
37+
console.log(useCount()); // 1
38+
console.log(useCount()); // 2
39+
console.log(useCount()); // 3
40+
});
4041

4142
runHookContext(() => {
42-
console.log(useCount()) // 1
43-
console.log(useCount()) // 2
44-
console.log(useCount()) // 3
45-
})
46-
````
43+
console.log(useCount()); // 1
44+
console.log(useCount()); // 2
45+
console.log(useCount()); // 3
46+
});
47+
```
48+
49+
`resetGlobalContext()`
50+
51+
This allows you to reset the global context. It can be very useful for testing purposes
52+
53+
```ts
54+
beforeEach(() => {
55+
resetGlobalContext();
56+
});
57+
58+
test("it should count", async () => {
59+
const count = useCount();
60+
expect(count).toBe(1); // true
61+
});
62+
63+
test("it should also count", async () => {
64+
const count = useCount();
65+
expect(count).toBe(1); // also true
66+
});
67+
```

0 commit comments

Comments
 (0)