From becf098580835083384735110520ae11951038aa Mon Sep 17 00:00:00 2001 From: Madeline Trotter Date: Tue, 5 Nov 2019 11:08:37 -0800 Subject: [PATCH] Disallow children prop except in 'unsafe' variant --- src/React/Basic/Hooks.purs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/React/Basic/Hooks.purs b/src/React/Basic/Hooks.purs index 84898cd..12c2579 100644 --- a/src/React/Basic/Hooks.purs +++ b/src/React/Basic/Hooks.purs @@ -1,5 +1,6 @@ module React.Basic.Hooks ( component + , unsafeComponent , memo , UseState , useState @@ -54,12 +55,23 @@ import Unsafe.Reference (unsafeRefEq) -- | lifecycles or render functions. component :: forall hooks props. + Lacks "children" props => Lacks "key" props => Lacks "ref" props => String -> ({ | props } -> Render Unit hooks JSX) -> Effect (ReactComponent { | props }) -component name renderFn = +component = unsafeComponent + +-- | Identical to `component`, but allows the unsafe use of the `children` prop. +unsafeComponent :: + forall hooks props. + Lacks "key" props => + Lacks "ref" props => + String -> + ({ | props } -> Render Unit hooks JSX) -> + Effect (ReactComponent { | props }) +unsafeComponent name renderFn = let c = unsafeReactFunctionComponent