Skip to content

Commit

Permalink
doc: useEffect progression
Browse files Browse the repository at this point in the history
  • Loading branch information
actionshrimp committed Apr 9, 2024
1 parent 185d697 commit a8ec4b3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ A notable exception is that when there is only one dependency, the relevant `use
useEffect1(effect, [|dep|])
```

However, as the length of the array is not specified, you could pass an array of arbitrary length, including the empty array, `[||]`.
However, as the length of the array is not specified, you could pass an array of arbitrary length, including the empty array, `[||]`. Try not to get caught out here when moving from `useEffect1` to `useEffect2` if the array has grown to include multiple elements of the same type in the meantime:

```reason
useEffect1(effect, [| 1 |])
/* ^^^ -- Compiles to javascript as `useEffect(effect, [1])` */
useEffect1(effect, [| 1, 2, 3 |])
/* ^^^ -- Compiles to javascript as `useEffect(effect, [1, 2, 3])` */
useEffect2(effect, [| 1, 2, 3 |], "foo")
/* ^^^ --- !! Compiles to javascript as `useEffect(effect, [ [1, 2, 3], "foo" ])` */
```

Reason also always opts for the safest form of a given hook as well. So `React.useState` in JS can take an initial value or a function that returns an initial value. The former cannot be used safely in all situations, so ReasonReact only supports the second form which takes a function and uses the return.

Expand Down

0 comments on commit a8ec4b3

Please sign in to comment.