File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,28 @@ useReducer initialState (Reducer reducer) =
331
331
332
332
foreign import data UseReducer :: Type -> Type -> Type -> Type
333
333
334
+ -- | Typically used to create a reference to a DOM element. Usage example:
335
+ -- |
336
+ -- | ```purs
337
+ -- | type NodeRef = Ref (Nullable Node)
338
+ -- |
339
+ -- | newNodeRef :: React.Hook (React.UseRef (Nullable Node)) NodeRef
340
+ -- | newNodeRef = React.useRef null
341
+ -- |
342
+ -- | myComponent :: Component {}
343
+ -- | myComponent = component "MyComponent" \_ -> React.do
344
+ -- | dialogRef :: NodeRef <- newNodeRef
345
+ -- | let myOnClose = resetDialog dialogRef
346
+ -- | pure $
347
+ -- | R.dialog
348
+ -- | { ref: dialogRef
349
+ -- | , children: [ R.form { ref: dialogRef } ]
350
+ -- | , onClose: myOnClose
351
+ -- | }
352
+ -- | ```
353
+ -- |
354
+ -- | Here, the reference is being connected with the `dialog` via `ref` field, and at
355
+ -- | the same time it's passed to `resetDialog` event handler.
334
356
useRef :: forall a . a -> Hook (UseRef a ) (Ref a )
335
357
useRef initialValue =
336
358
unsafeHook do
@@ -575,4 +597,4 @@ foreign import useSyncExternalStore3_ :: forall a. EffectFn3
575
597
(EffectFn1 (Effect Unit ) (Effect Unit )) -- subscribe
576
598
(Effect a ) -- getSnapshot
577
599
(Effect a ) -- getServerSnapshot
578
- a
600
+ a
You can’t perform that action at this time.
0 commit comments