Skip to content

Commit a69a979

Browse files
committed
Update documentation after #15 and #14
1 parent b4f9e49 commit a69a979

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

react-facet/docs/api/equality-checks.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ console.log(equalityCheck(1)) // false
2727
console.log(equalityCheck(1)) // true
2828
```
2929

30-
## `shallowObjectEqualityCheck`
30+
## `shallowObjectEqualityCheck` and `nullableShallowObjectEqualityCheck`
3131

3232
Equality check that verifies the values of each key of an object.
33-
Each value must be a primitive (boolean, number or string)
33+
34+
Each value must be a primitive (boolean, number or string).
35+
36+
There is also a variant that supports "nullable values" (`undefined` and `null`).
3437

3538
```tsx
3639
import { shallowObjectEqualityCheck } from '@react-facet/equality-checks'
@@ -44,9 +47,11 @@ console.log(equalityCheck({ name: 'Steve', height: 2 })) // false
4447
console.log(equalityCheck({ name: 'Steve', height: 2 })) // true
4548
```
4649

47-
## `shallowObjectArrayEqualityCheck`
50+
## `shallowObjectArrayEqualityCheck` and `nullableShallowObjectArrayEqualityCheck`
4851

49-
Does a shallow object equality check for each element in an array
52+
Does a shallow object equality check for each element in an array.
53+
54+
There is also a variant that supports "nullable values" (`undefined` and `null`).
5055

5156
```tsx
5257
import { shallowObjectArrayEqualityCheck } from '@react-facet/equality-checks'
@@ -61,9 +66,11 @@ console.log(equalityCheck([{ name: 'Alex' }])) // true
6166
console.log(equalityCheck([{ name: 'Steve' }])) // false
6267
```
6368

64-
## `shallowArrayEqualityCheck`
69+
## `shallowArrayEqualityCheck` and `nullableShallowArrayEqualityCheck`
70+
71+
Shallow equality check of primitives in an array.
6572

66-
Shallow equality check of primitives in an array
73+
There is also a variant that supports "nullable values" (`undefined` and `null`).
6774

6875
```tsx
6976
import { shallowArrayEqualityCheck } from '@react-facet/equality-checks'

react-facet/docs/api/hooks.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const Form = ({ onSubmit, initialValue }) => {
3838
onSubmit(currentValue)
3939
},
4040
[onSubmit],
41-
value,
41+
[value],
4242
)
4343

4444
return (
@@ -53,7 +53,7 @@ const Form = ({ onSubmit, initialValue }) => {
5353

5454
## `useFacetCallback`
5555

56-
The `useFacetCallback` hook is similar to React’s `useCallback` in that it allows you to create a memoized callback that will only be updated if some of the explicit dependencies change. On top of that, `useFacetCallback` allows you to pass in a Facet and get the current value of that facet in the callback body.
56+
The `useFacetCallback` hook is similar to React’s `useCallback` in that it allows you to create a memoized callback that will only be updated if some of the explicit dependencies change. On top of that, `useFacetCallback` allows you to pass one or more Facets and get the current values of those facets in the callback body.
5757

5858
Say for example that you have a small form, and want to create a handler for the Submit action. You need to have access to the current value of a facet that stores the `value` of an input field in order to send that value back to the parent component when the `Submit` button of the form. `useFacetCallback` allows you to create such handler, which will always have access to the current value of the facet.
5959

@@ -73,7 +73,7 @@ const Form = ({ onSubmit, initialValue }) => {
7373
onSubmit(currentValue)
7474
},
7575
[onSubmit],
76-
value,
76+
[value],
7777
)
7878

7979
return (
@@ -88,9 +88,9 @@ const Form = ({ onSubmit, initialValue }) => {
8888

8989
## `useFacetEffect`
9090

91-
The `useFacetEffect` hook gives you a way of performing some imperative action (effect) whenever the underlying facet is updated. It is very similar in structure and goal to React’s own `useEffect`.
91+
The `useFacetEffect` hook gives you a way of performing some imperative action (effect) whenever the underlying facets are updated. It is very similar in structure and goal to React’s own `useEffect`.
9292

93-
Like `useEffect`, `useFacetEffect` takes an effect function to be called when the updates happen, a dependency list, and finally a facet.
93+
Like `useEffect`, `useFacetEffect` takes an effect function to be called when the updates happen, a dependency list, and finally one or more facets.
9494

9595
```tsx
9696
const Logger = ({ shouldLog }) => {
@@ -103,14 +103,14 @@ const Logger = ({ shouldLog }) => {
103103
}
104104
},
105105
[shouldLog],
106-
statusFacet,
106+
[statusFacet],
107107
)
108108

109109
return <span>{shouldLog ? 'Logger is active' : 'Logger is disabled'}</span>
110110
}
111111
```
112112

113-
It also supports a cleanup function that can be returned by the effect function. This cleanup is called whenever any of the dependencies or the facet has changed or when the component is unmounted. In short, it behaves exactly like React’s `useEffect`.
113+
It also supports a cleanup function that can be returned by the effect function. This cleanup is called whenever any of the dependencies or the facets have changed or when the component is unmounted. In short, it behaves exactly like React’s `useEffect`.
114114

115115
```tsx
116116
const Logger = ({ shouldLog }) => {
@@ -128,7 +128,7 @@ const Logger = ({ shouldLog }) => {
128128
return () => clearTimeout(timerId)
129129
},
130130
[shouldLog],
131-
statusFacet,
131+
[statusFacet],
132132
)
133133

134134
return <span>{shouldLog ? 'Logger is active' : 'Logger is disabled'}</span>

react-facet/docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const UpdateLogin = ({ onSubmit }) => {
117117
onSubmit(values)
118118
},
119119
[onSubmit],
120-
temporaryValues,
120+
[temporaryValues],
121121
)
122122

123123
return (

react-facet/docs/rendering/using-facets-manually.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const Counter = () => {
2323
ref.current.textContent = `${counterValue}`
2424
},
2525
[],
26-
counter,
26+
[counter],
2727
)
2828

2929
const handleClick = useCallback(() => {

0 commit comments

Comments
 (0)