@mittwald/flow-react-components 1.6.3 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MIGRATION.md CHANGED
@@ -28,6 +28,62 @@ The CLI's own output does detect it and prints the right form.
28
28
 
29
29
  ---
30
30
 
31
+ <a id="list-item-callbacks-without-hooks"></a>
32
+
33
+ ## ListItem: `href` and `textValue` must not call hooks
34
+
35
+ **Since `1.6.0`** · migration · manual change · also applies to
36
+ `@mittwald/flow-remote-react-components`
37
+
38
+ Since 1.6.0 a list skips rendering items that have not changed. To decide that,
39
+ it calls `href` and `textValue` for every item on each render of the list —
40
+ outside the item's own render and as often as it needs. Hooks inside these
41
+ callbacks used to run inside the item and happened to work; now they run in
42
+ another component a varying number of times, and React fails with
43
+ `Rendered more hooks than during the previous render`
44
+ ([React error 310](https://react.dev/errors/310)) as soon as the list
45
+ re-renders.
46
+
47
+ ```diff
48
+ + const projectId = projectGhost.id.use();
49
+ +
50
+ <List.Item
51
+ - href={(c) => buildHref(projectGhost.id.use(), c.id)}
52
+ + href={(c) => buildHref(projectId, c.id)}
53
+ >
54
+ ```
55
+
56
+ For a value that depends on the item, call the hook once and let it return a
57
+ function:
58
+
59
+ ```diff
60
+ + const isNew = useNewEntriesTester();
61
+ +
62
+ <List.Item
63
+ - defaultExpanded={(entry) => entry.useIsNew()}
64
+ + defaultExpanded={(entry) => isNew(entry)}
65
+ >
66
+ ```
67
+
68
+ `defaultExpanded` is still called inside the item, but it is read on mount only
69
+ — keep it free of hooks as well. The item's render function (its children) is
70
+ unaffected: it renders inside the item and may call hooks.
71
+
72
+ ESLint's `react-hooks/rules-of-hooks` does not catch most of these cases: it
73
+ does not treat a method call such as `ghost.id.use()` or `entry.useIsNew()` as a
74
+ hook.
75
+
76
+ **Apply:** Find `ListItem` elements — including the `Item` of a `typedList()` —
77
+ whose `href`, `textValue` or `defaultExpanded` callback calls a hook: a `use…()`
78
+ function, `React.use()`, or a hook-like method such as a ghost's `.use()`. Call
79
+ the hook once in the component that renders the list, store the result in a
80
+ variable, and read that variable inside the callback. Where the value depends on
81
+ the item, have the hook return a function (e.g. a tester or a URL builder) and
82
+ call that function with the item. Hooks in the item's render function (its
83
+ children) are fine and stay.
84
+
85
+ ---
86
+
31
87
  <a id="accordion-variant-deprecated"></a>
32
88
 
33
89
  ## Accordion: `variant` deprecated