You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In effective usage of React, callbacks are passed around as component properties.
139
139
Due to the ease of function creation in Scala it is often the case that functions are created inline and thus
140
140
provide no means of determining whether a component can safely skip its update.
141
141
142
-
`ReusableFn` exists as a solution. It is a wrapper around a function that allows it to be both reused, and curried in a way that allows reuse.
142
+
`Reusable.fn` exists as a solution. It is a wrapper around a function that allows it to be both reused, and curried in a way that allows reuse.
143
143
144
144
#### Usage
145
145
146
-
1. Just wrap `ReusableFn` around your function.
147
-
2. Store the `ReusableFn` as a `val` somewhere outside of your `render` function, usually in the body of your backend class.
148
-
3. Replace the callback (say `A => B`) in components' props, to take a `ReusableFn[A, B]` or the shorthand `A ~=> B`.
149
-
4. Treat the `ReusableFn` as you would a normal function, save for one difference: application is curried (or Schönfinkel'ed), and each curried argument must have `Reusability`.
146
+
1. Just wrap `Reusable.fn` around your function.
147
+
2. Store the `Reusable.fn` as a `val` somewhere outside of your `render` function, usually in the body of your backend class.
148
+
3. Replace the callback (say `A => B`) in components' props, to take a `Reusable.fn[A, B]` or the shorthand `A ~=> B`.
149
+
4. Treat the `Reusable.fn` as you would a normal function, save for one difference: application is curried (or Schönfinkel'ed), and each curried argument must have `Reusability`.
150
150
151
151
#### Example
152
152
@@ -164,7 +164,7 @@ val topComponent = ScalaComponent.build[State]("Demo")
164
164
165
165
classBackend($: BackendScope[_, State]) {
166
166
167
-
valupdateUser=ReusableFn((id: PersonId, data: PersonData) =>// ← Create a 2-arg fn
167
+
valupdateUser=Reusable.fn((id: PersonId, data: PersonData) =>// ← Create a 2-arg fn
168
168
$.modState(map => map.updated(id, data)))
169
169
170
170
defrender(state: State) =
@@ -190,7 +190,7 @@ val personEditor = ScalaComponent.build[PersonEditorProps]("PersonEditor")
190
190
191
191
#### WARNING!
192
192
193
-
**DO NOT** feed the `ReusableFn(...)` constructor a function directly *derived* from a component's props or state.
193
+
**DO NOT** feed the `Reusable.fn(...)` constructor a function directly *derived* from a component's props or state.
194
194
Access to props/state on the right-hand side of the function args is ok but if the function itself is a result of the
195
195
props/state, the function will forever be based on data that can go stale.
0 commit comments