File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 11module React.Basic.Hooks
22 ( component
33 , componentWithChildren
4+ , componentFromHook
45 , ReactChildren
56 , memo
67 , UseState
@@ -77,6 +78,22 @@ componentWithChildren ::
7778 Effect (ReactComponent { children :: ReactChildren children | props } )
7879componentWithChildren = unsafeComponent
7980
81+ -- | Convert a hook to a render-prop component. The value returned from the
82+ -- | hook will be passed to the `render` prop, a function from that value
83+ -- | to `JSX`.
84+ -- |
85+ -- | This function is useful for consuming a hook within a non-hook component.
86+ componentFromHook ::
87+ forall hooks props r .
88+ Lacks " children" props =>
89+ Lacks " key" props =>
90+ Lacks " ref" props =>
91+ String ->
92+ ({ render :: r -> JSX | props } -> Render Unit hooks r ) ->
93+ Effect (ReactComponent { render :: r -> JSX | props } )
94+ componentFromHook name propsToHook = do
95+ component name \props -> map props.render $ propsToHook props
96+
8097unsafeComponent ::
8198 forall hooks props .
8299 Lacks " key" props =>
You can’t perform that action at this time.
0 commit comments