11module React.Basic.Hooks
22 ( component
3- , unsafeComponent
3+ , componentWithChildren
4+ , ReactChildren
45 , memo
56 , UseState
67 , useState
@@ -52,7 +53,8 @@ import Unsafe.Reference (unsafeRefEq)
5253-- | Creating components is effectful because React uses the function
5354-- | instance as the component's "identity" or "type". Components should
5455-- | be created during a bootstrap phase and not within component
55- -- | lifecycles or render functions.
56+ -- | lifecycles or render functions. See `componentWithChildren` if
57+ -- | you need to use the `children` prop.
5658component ::
5759 forall hooks props .
5860 Lacks " children" props =>
@@ -63,7 +65,18 @@ component ::
6365 Effect (ReactComponent { | props } )
6466component = unsafeComponent
6567
66- -- | Identical to `component`, but allows the unsafe use of the `children` prop.
68+ -- | Create a React component given a display name and render function.
69+ -- | This is the same as `component` but allows the use of the `children`
70+ -- | prop.
71+ componentWithChildren ::
72+ forall hooks props children .
73+ Lacks " key" props =>
74+ Lacks " ref" props =>
75+ String ->
76+ ({ children :: ReactChildren children | props } -> Render Unit hooks JSX ) ->
77+ Effect (ReactComponent { children :: ReactChildren children | props } )
78+ componentWithChildren = unsafeComponent
79+
6780unsafeComponent ::
6881 forall hooks props .
6982 Lacks " key" props =>
@@ -89,6 +102,13 @@ unsafeDiscardRenderEffects = unsafeCoerce
89102unsafeReactFunctionComponent :: forall props . EffectFn1 props JSX -> ReactComponent props
90103unsafeReactFunctionComponent = unsafeCoerce
91104
105+ data ReactChildren a
106+
107+ foreign import reactChildrenToArray :: forall a . ReactChildren a -> Array a
108+
109+ reactChildrenFromArray :: forall a . Array a -> ReactChildren a
110+ reactChildrenFromArray = unsafeCoerce
111+
92112memo ::
93113 forall props .
94114 Effect (ReactComponent props ) ->
0 commit comments