From e4b862f1b57836e7fc0f4c42787708d2097ba8dd Mon Sep 17 00:00:00 2001 From: Ryan Trinkle Date: Tue, 4 Jul 2023 13:01:15 -0400 Subject: [PATCH] Use FromJSVal for props --- src/React/Component.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/React/Component.hs b/src/React/Component.hs index b21821b..1b8d5b7 100644 --- a/src/React/Component.hs +++ b/src/React/Component.hs @@ -8,13 +8,16 @@ import React.JSaddle import React.Types --TODO: The Hook section shouldn't have any control flow to it; probably it also shouldn't depend on props except in specific ways -component :: (JSVal -> Hook Element) -> ReaderT React JSM (Component JSVal ()) +component :: FromJSVal props => (props -> Hook Element) -> ReaderT React JSM (Component props ()) component hook = do react <- ask f <- lift $ function' $ \_ _ args -> flip runReaderT react $ do - let props = case args of + let propsVal = case args of [] -> jsUndefined arg0 : _ -> arg0 + props <- liftJSM $ fromJSVal propsVal >>= \case + Nothing -> fail "Invalid props" + Just props -> pure props e <- unHook $ hook props unElement e pure $ Component f