-
Notifications
You must be signed in to change notification settings - Fork 67
/
hooks.dart
651 lines (621 loc) · 22.2 KB
/
hooks.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
@JS()
library hooks;
import 'package:js/js.dart';
import 'package:meta/meta.dart';
import 'package:react/react.dart';
import 'package:react/react_client/react_interop.dart';
/// A setter function returned as the second item in the result of a JS useState call,
/// which accepts either a value or an updater function.
///
/// If Dart had type unions, the typing would be: `void Function(T|(T Function(T)) valueOrUpdater)`
///
/// We could make this generic, but the generic value wouldn't be used at all since the argument
/// can only be expressed as `dynamic`.
typedef _JsStateHookSetter/*<T>*/ = void Function(dynamic /*T|(T Function(T))*/ valueOrUpdater);
/// The return value of [useState].
///
/// The current value of the state is available via [value] and
/// functions to update it are available via [set] and [setWithUpdater].
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// Learn more: <https://reactjs.org/docs/hooks-state.html>.
@sealed
class StateHook<T> {
/// The first item of the pair returned by [React.useState].
final T _value;
/// The second item in the pair returned by [React.useState].
final _JsStateHookSetter _setValue;
StateHook._(this._value, this._setValue);
/// The current value of the state.
///
/// See: <https://reactjs.org/docs/hooks-reference.html#usestate>.
T get value => _value;
/// Updates [value] to [newValue].
///
/// See: <https://reactjs.org/docs/hooks-state.html#updating-state>.
void set(T newValue) => _setValue(newValue);
/// Updates [value] to the return value of [computeNewValue].
///
/// See: <https://reactjs.org/docs/hooks-reference.html#functional-updates>.
void setWithUpdater(T Function(T oldValue) computeNewValue) => _setValue(allowInterop(computeNewValue));
}
/// Adds local state to a [DartFunctionComponent]
/// by returning a [StateHook] with [StateHook.value] initialized to [initialValue].
///
/// > __Note:__ If the [initialValue] is expensive to compute, [useStateLazy] should be used instead.
///
/// __Example__:
///
/// ```dart
/// UseStateTestComponent(Map props) {
/// final count = useState(0);
///
/// return react.div({}, [
/// count.value,
/// react.button({'onClick': (_) => count.set(0)}, ['Reset']),
/// react.button({
/// 'onClick': (_) => count.setWithUpdater((prev) => prev + 1),
/// }, ['+']),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-state.html>.
StateHook<T> useState<T>(T initialValue) {
final result = React.useState(initialValue);
return StateHook._(result[0] as T, result[1] as _JsStateHookSetter);
}
/// Adds local state to a [DartFunctionComponent]
/// by returning a [StateHook] with [StateHook.value] initialized to the return value of [init].
///
/// __Example__:
///
/// ```dart
/// UseStateTestComponent(Map props) {
/// final count = useStateLazy(() {
/// var initialState = someExpensiveComputation(props);
/// return initialState;
/// }));
///
/// return react.div({}, [
/// count.value,
/// react.button({'onClick': (_) => count.set(0)}, ['Reset']),
/// react.button({'onClick': (_) => count.set((prev) => prev + 1)}, ['+']),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#lazy-initial-state>.
StateHook<T> useStateLazy<T>(T Function() init) {
final result = React.useState(allowInterop(init));
return StateHook._(result[0] as T, result[1] as _JsStateHookSetter);
}
/// Runs [sideEffect] after every completed render of a [DartFunctionComponent].
///
/// If [dependencies] are given, [sideEffect] will only run if one of the [dependencies] have changed.
/// [sideEffect] may return a cleanup function that is run before the component unmounts or re-renders.
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// UseEffectTestComponent(Map props) {
/// final count = useState(1);
/// final evenOdd = useState('even');
///
/// useEffect(() {
/// if (count.value % 2 == 0) {
/// evenOdd.set('even');
/// } else {
/// evenOdd.set('odd');
/// }
/// return () {
/// print('count is changing... do some cleanup if you need to');
/// };
///
/// // This dependency prevents the effect from running every time [evenOdd.value] changes.
/// }, [count.value]);
///
/// return react.div({}, [
/// react.p({}, ['${count.value} is ${evenOdd.value}']),
/// react.button({'onClick': (_) => count.set(count.value + 1)}, ['+']),
/// ]);
/// }
/// ```
///
/// See: <https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects>.
void useEffect(dynamic Function() sideEffect, [List<Object?>? dependencies]) {
final wrappedSideEffect = allowInterop(() {
final result = sideEffect();
if (result is Function) {
return allowInterop(result);
}
/// When no cleanup function is returned, [sideEffect] returns undefined.
return jsUndefined;
});
return React.useEffect(wrappedSideEffect, dependencies);
}
/// The return value of [useReducer].
///
/// The current state is available via [state] and action dispatcher is available via [dispatch].
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usereducer>.
@sealed
class ReducerHook<TState, TAction, TInit> {
/// The first item of the pair returned by [React.useReducer].
final TState _state;
/// The second item in the pair returned by [React.useReducer].
final void Function(TAction) _dispatch;
ReducerHook._(this._state, this._dispatch);
/// The current state map of the component.
///
/// See: <https://reactjs.org/docs/hooks-reference.html#usereducer>.
TState get state => _state;
/// Dispatches [action] and triggers stage changes.
///
/// > __Note:__ The dispatch function identity is stable and will not change on re-renders.
///
/// See: <https://reactjs.org/docs/hooks-reference.html#usereducer>.
void dispatch(TAction action) => _dispatch(action);
}
/// Initializes state of a [DartFunctionComponent] to [initialState] and creates a `dispatch` method.
///
/// __Example__:
///
/// ```dart
/// Map reducer(Map state, Map action) {
/// switch (action['type']) {
/// case 'increment':
/// return {...state, 'count': state['count'] + 1};
/// case 'decrement':
/// return {...state, 'count': state['count'] - 1};
/// default:
/// return state;
/// }
/// }
///
/// UseReducerTestComponent(Map props) {
/// final state = useReducer(reducer, {'count': 0});
///
/// return react.Fragment({}, [
/// state.state['count'],
/// react.button({
/// 'onClick': (_) => state.dispatch({'type': 'increment'})
/// }, [
/// '+'
/// ]),
/// react.button({
/// 'onClick': (_) => state.dispatch({'type': 'decrement'})
/// }, [
/// '-'
/// ]),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usereducer>.
ReducerHook<TState, TAction, TInit> useReducer<TState, TAction, TInit>(
TState Function(TState state, TAction action) reducer, TState initialState) {
final result = React.useReducer(allowInterop(reducer), initialState);
return ReducerHook._(result[0] as TState, result[1] as void Function(TAction));
}
/// Initializes state of a [DartFunctionComponent] to `init(initialArg)` and creates `dispatch` method.
///
/// __Example__:
///
/// ```dart
/// Map initializeCount(int initialValue) {
/// return {'count': initialValue};
/// }
///
/// Map reducer(Map state, Map action) {
/// switch (action['type']) {
/// case 'increment':
/// return {...state, 'count': state['count'] + 1};
/// case 'decrement':
/// return {...state, 'count': state['count'] - 1};
/// case 'reset':
/// return initializeCount(action['payload']);
/// default:
/// return state;
/// }
/// }
///
/// UseReducerTestComponent(Map props) {
/// final ReducerHook<Map, Map, int> state = useReducerLazy(reducer, props['initialCount'], initializeCount);
///
/// return react.Fragment({}, [
/// state.state['count'],
/// react.button({
/// 'onClick': (_) => state.dispatch({'type': 'increment'})
/// }, [
/// '+'
/// ]),
/// react.button({
/// 'onClick': (_) => state.dispatch({'type': 'decrement'})
/// }, [
/// '-'
/// ]),
/// react.button({
/// 'onClick': (_) => state.dispatch({
/// 'type': 'reset',
/// 'payload': props['initialCount'],
/// })
/// }, [
/// 'reset'
/// ]),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#lazy-initialization>.
ReducerHook<TState, TAction, TInit> useReducerLazy<TState, TAction, TInit>(
TState Function(TState state, TAction action) reducer, TInit initialArg, TState Function(TInit) init) {
final result = React.useReducer(allowInterop(reducer), initialArg, allowInterop(init));
return ReducerHook._(result[0] as TState, result[1] as void Function(TAction));
}
/// Returns a memoized version of [callback] that only changes if one of the [dependencies] has changed.
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// UseCallbackTestComponent(Map props) {
/// final count = useState(0);
/// final delta = useState(1);
///
/// var increment = useCallback((_) {
/// count.setWithUpdater((prev) => prev + delta.value);
/// }, [delta.value]);
///
/// var incrementDelta = useCallback((_) {
/// delta.setWithUpdater((prev) => prev + 1);
/// }, []);
///
/// return react.div({}, [
/// react.div({}, ['Delta is ${delta.value}']),
/// react.div({}, ['Count is ${count.value}']),
/// react.button({'onClick': increment}, ['Increment count']),
/// react.button({'onClick': incrementDelta}, ['Increment delta']),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usecallback>.
T useCallback<T extends Function>(T callback, List dependencies) =>
React.useCallback(allowInterop(callback), dependencies) as T;
/// Returns the value of the nearest [Context.Provider] for the provided [context] object every time that context is
/// updated.
///
/// The usage is similar to that of a [Context.Consumer] in that the return type of [useContext] is dependent upon
/// the typing of the value passed into [createContext] and [Context.Provider].
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// Context countContext = createContext(0);
///
/// UseCallbackTestComponent(Map props) {
/// final count = useContext(countContext);
///
/// return react.div({}, [
/// react.div({}, ['The count from context is $count']), // initially renders: 'The count from context is 0'
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usecontext>.
T useContext<T>(Context<T> context) => ContextHelpers.unjsifyNewContext(React.useContext(context.jsThis)) as T;
/// Returns an empty mutable [Ref] object.
///
/// To initialize a ref with a value, use [useRefInit] instead.
///
/// Changes to the [Ref.current] property do not cause the containing [DartFunctionComponent] to re-render.
///
/// The returned [Ref] object will persist for the full lifetime of the [DartFunctionComponent].
/// Compare to [createRef] which returns a new [Ref] object on each render.
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// UseRefTestComponent(Map props) {
/// final inputValue = useState('');
///
/// final inputRef = useRef<InputElement>();
/// final prevInputValueRef = useRef<String>();
///
/// useEffect(() {
/// prevInputValueRef.current = inputValue.value;
/// });
///
/// return react.Fragment({}, [
/// react.p({}, ['Current Input: ${inputValue.value}, Previous Input: ${prevInputValueRef.current}']),
/// react.input({'ref': inputRef}),
/// react.button({'onClick': (_) => inputValue.set(inputRef.current.value)}, ['Update']),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#useref>.
Ref<T?> useRef<T>([
@Deprecated('Use `useRefInit` instead to create refs with initial values.'
' Since the argument to useRefInit is required, it can be used to create a Ref that holds a non-nullable type,'
' whereas this function can only create Refs with nullable type arguments.')
T? initialValue,
]) =>
useRefInit(initialValue);
/// Returns a mutable [Ref] object with [Ref.current] property initialized to [initialValue].
///
/// Changes to the [Ref.current] property do not cause the containing [DartFunctionComponent] to re-render.
///
/// The returned [Ref] object will persist for the full lifetime of the [DartFunctionComponent].
/// Compare to [createRef] which returns a new [Ref] object on each render.
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// UseRefTestComponent(Map props) {
/// final countRef = useRefInit(1);
///
/// handleClick([_]) {
/// ref.current = ref.current + 1;
/// window.alert('You clicked ${ref.current} times!');
/// }
///
/// return react.Fragment({}, [
/// react.button({'onClick': handleClick}, ['Click me!']),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#useref>.
Ref<T> useRefInit<T>(T initialValue) => Ref.fromJs(React.useRef(initialValue));
/// Returns a memoized version of the return value of [createFunction].
///
/// If one of the [dependencies] has changed, [createFunction] is run during rendering of the [DartFunctionComponent].
/// This optimization helps to avoid expensive calculations on every render.
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// UseMemoTestComponent(Map props) {
/// final count = useState(0);
///
/// final fib = useMemo(
/// () => fibonacci(count.value),
///
/// /// This dependency prevents [fib] from being re-calculated every time the component re-renders.
/// [count.value],
/// );
///
/// return react.Fragment({}, [
/// react.div({}, ['Fibonacci of ${count.value} is $fib']),
/// react.button({'onClick': (_) => count.setWithUpdater((prev) => prev + 1)}, ['+']),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usememo>.
T useMemo<T>(T Function() createFunction, [List<dynamic>? dependencies]) =>
React.useMemo(allowInterop(createFunction), dependencies) as T;
/// Runs [sideEffect] synchronously after a [DartFunctionComponent] renders, but before the screen is updated.
///
/// Compare to [useEffect] which runs [sideEffect] after the screen updates.
/// Prefer the standard [useEffect] when possible to avoid blocking visual updates.
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// UseLayoutEffectTestComponent(Map props) {
/// final width = useState(0);
/// final height = useState(0);
///
/// Ref textareaRef = useRef();
///
/// useLayoutEffect(() {
/// width.set(textareaRef.current.clientWidth);
/// height.set(textareaRef.current.clientHeight);
/// });
///
/// return react.Fragment({}, [
/// react.div({}, ['textarea width: ${width.value}']),
/// react.div({}, ['textarea height: ${height.value}']),
/// react.textarea({'onClick': (_) => width.set(0), 'ref': textareaRef,}),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#uselayouteffect>.
void useLayoutEffect(dynamic Function() sideEffect, [List<Object?>? dependencies]) {
final wrappedSideEffect = allowInterop(() {
final result = sideEffect();
if (result is Function) {
return allowInterop(result);
}
/// When no cleanup function is returned, [sideEffect] returns undefined.
return jsUndefined;
});
return React.useLayoutEffect(wrappedSideEffect, dependencies);
}
/// Customizes the [ref] value that is exposed to parent components when using [forwardRef2] by setting `ref.current`
/// to the return value of [createHandle].
///
/// In most cases, imperative code using refs should be avoided.
/// For more information, see <https://reactjs.org/docs/refs-and-the-dom.html#when-to-use-refs>.
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// class FancyInputApi {
/// final void Function() focus;
/// FancyInputApi(this.focus);
/// }
///
/// final FancyInput = react.forwardRef2((props, ref) {
/// final inputRef = useRef<InputElement>();
///
/// useImperativeHandle(
/// ref,
/// () => FancyInputApi(() => inputRef.current.focus()),
///
/// /// Because the return value of [createHandle] never changes, it is not necessary for [ref.current]
/// /// to be re-set on each render so this dependency list is empty.
/// [],
/// );
///
/// return react.input({
/// 'ref': inputRef,
/// 'value': props['value'],
/// 'onChange': (e) => props['update'](e.target.value),
/// });
/// });
///
/// UseImperativeHandleTestComponent(Map props) {
/// final inputValue = useState('');
/// final fancyInputRef = useRef<FancyInputApi>();
///
/// return react.Fragment({}, [
/// FancyInput({
/// 'value': inputValue.value,
/// 'update': inputValue.set,
/// 'ref': fancyInputRef,
/// }, []),
/// react.button({'onClick': (_) => fancyInputRef.current.focus()}, ['Focus Input']),
/// ]);
/// }
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#useimperativehandle>.
void useImperativeHandle(dynamic ref, dynamic Function() createHandle, [List<dynamic>? dependencies]) =>
// ref will be a JsRef in forwardRef2, or a Ref in forwardRef. (Or null if no ref is provided)
//
// For some reason the ref argument to React.forwardRef is usually a JsRef object no matter the input ref type,
// but according to React the ref argument to useImperativeHandle and React.forwardRef can be any ref type...
// - https://github.com/facebook/flow/blob/master@%7B2020-09-08%7D/lib/react.js#L373
// - https://github.com/facebook/flow/blob/master@%7B2020-09-08%7D/lib/react.js#L305
// and not just a ref object, so we type it as dynamic here.
React.useImperativeHandle(ref is Ref ? ref.jsRef : ref, allowInterop(createHandle), dependencies);
/// Displays [value] as a label for a custom hook in React DevTools.
///
/// To [defer formatting](https://reactjs.org/docs/hooks-reference.html#defer-formatting-debug-values) [value] until
/// the hooks are inspected, use optional [format] function.
///
/// > __Note:__ there are two [rules for using Hooks](https://reactjs.org/docs/hooks-rules.html):
/// >
/// > * Only call Hooks at the top level.
/// > * Only call Hooks from inside a [DartFunctionComponent].
///
/// __Example__:
///
/// ```dart
/// class ChatAPI {
/// static void subscribeToFriendStatus(int id, Function handleStatusChange) =>
/// handleStatusChange({'isOnline': id % 2 == 0 ? true : false});
///
/// static void unsubscribeFromFriendStatus(int id, Function handleStatusChange) =>
/// handleStatusChange({'isOnline': false});
/// }
///
/// // Custom Hook
/// StateHook useFriendStatus(int friendID) {
/// final isOnline = useState(false);
///
/// void handleStatusChange(Map status) {
/// isOnline.set(status['isOnline']);
/// }
///
/// useEffect(() {
/// ChatAPI.subscribeToFriendStatus(friendID, handleStatusChange);
/// return () {
/// ChatAPI.unsubscribeFromFriendStatus(friendID, handleStatusChange);
/// };
/// });
///
/// // Use format function to avoid unnecessarily formatting `isOnline` when the hooks aren't inspected in React DevTools.
/// useDebugValue<bool>(isOnline.value, (isOnline) => isOnline ? 'Online' : 'Not Online');
///
/// return isOnline;
/// }
///
/// final FriendListItem = react.registerFunctionComponent((props) {
/// final isOnline = useFriendStatus(props['friend']['id']);
///
/// return react.li({
/// 'style': {'color': isOnline.value ? 'green' : 'black'}
/// }, [
/// props['friend']['name']
/// ]);
/// }, displayName: 'FriendListItem');
///
/// final UseDebugValueTestComponent = react.registerFunctionComponent(
/// (Map props) => react.Fragment({}, [
/// FriendListItem({
/// 'friend': {'id': 1, 'name': 'user 1'}
/// }, []),
/// FriendListItem({
/// 'friend': {'id': 2, 'name': 'user 2'}
/// }, []),
/// FriendListItem({
/// 'friend': {'id': 3, 'name': 'user 3'}
/// }, []),
/// FriendListItem({
/// 'friend': {'id': 4, 'name': 'user 4'}
/// }, []),
/// ]),
/// displayName: 'useDebugValueTest');
/// ```
///
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usedebugvalue>.
dynamic useDebugValue<T>(T value, [dynamic Function(T)? format]) {
if (format == null) {
return React.useDebugValue(value);
}
return React.useDebugValue(value, allowInterop(format));
}