@@ -4,17 +4,16 @@ import Prelude
44import Data.Foldable (find )
55import Data.Maybe (Maybe (..))
66import Data.Newtype (class Newtype , un )
7- import Effect (Effect )
87import Effect.Aff (Aff , Milliseconds (..), delay , error , message , throwError )
98import React.Basic.DOM as R
109import React.Basic.DOM.Events (capture_ )
1110import React.Basic.Events (handler_ )
12- import React.Basic.Hooks (JSX , ReactComponent , component , element , fragment , useState , (/\))
11+ import React.Basic.Hooks (Component , component , fragment , useState , (/\))
1312import React.Basic.Hooks as React
1413import React.Basic.Hooks.Aff (useAff )
1514import React.Basic.Hooks.ErrorBoundary (mkErrorBoundary )
1615
17- mkExample :: Effect ( ReactComponent { } )
16+ mkExample :: Component Unit
1817mkExample = do
1918 errorBoundary <- mkErrorBoundary " AffExErrorBoundary"
2019 catDetails <- mkCatDetails
@@ -32,24 +31,23 @@ mkExample = do
3231 [ catKeyList catKey setCatKey
3332 , case catKey of
3433 Nothing -> mempty
35- Just k -> catDetails { catKey: k }
34+ Just k -> catDetails k
3635 ]
3736 ]
3837 where
3938 -- This component is the main `useAff` demo. It receives a key
4039 -- as a prop and renders both the loading state and the final
4140 -- result.
42- mkCatDetails :: Effect ({ catKey :: Key Cat } -> JSX )
43- mkCatDetails =
44- map element do
45- component " CatDetails" \{ catKey } -> React .do
46- catState <- useAff catKey $ fetch catKey
47- pure
48- $ R .p_
49- [ case map entity catState of
50- Nothing -> R .text " Loading..."
51- Just (Cat { name }) -> R .text $ " A cat named " <> name
52- ]
41+ mkCatDetails :: Component (Key Cat )
42+ mkCatDetails = do
43+ component " CatDetails" \catKey -> React .do
44+ catState <- useAff catKey $ fetch catKey
45+ pure
46+ $ R .p_
47+ [ case map entity catState of
48+ Nothing -> R .text " Loading..."
49+ Just (Cat { name }) -> R .text $ " A cat named " <> name
50+ ]
5351
5452 renderAppError error resetApp =
5553 fragment
0 commit comments