@@ -23,6 +23,8 @@ module React.Basic
2323 , Ref
2424 , ReactContext
2525 , createContext
26+ , contextConsumer
27+ , contextProvider
2628 , provider
2729 , consumer
2830 ) where
@@ -373,14 +375,11 @@ foreign import toReactComponent
373375 -> { render :: Self props state -> JSX | spec }
374376 -> ReactComponent { | jsProps }
375377
376- type ReactContext a =
377- { provider :: ReactComponent { value :: a , children :: Array JSX }
378- , consumer :: ReactComponent { children :: a -> Array JSX }
379- }
378+ foreign import data ReactContext :: Type -> Type
380379
381380-- | Create a `ReactContext` given a default value. Use `provider` and `consumer`
382- -- | to provide and consume context values. Alternatively, use the fields of
383- -- | `ReactContext ` directly if a `ReactComponent` is required for interop.
381+ -- | to provide and consume context values. Alternatively, use `contextProvider`
382+ -- | and `contextConsumer ` directly if a `ReactComponent` is required for interop.
384383-- |
385384-- | ```purs
386385-- | render self =
@@ -398,21 +397,31 @@ type ReactContext a =
398397-- | ```
399398-- |
400399-- | __*See also:* `provider`, `consumer`, React's documentation regarding Context__
401- foreign import createContext :: forall a . a -> ReactContext a
400+ foreign import createContext :: forall a . a -> Effect (ReactContext a )
401+
402+ foreign import contextProvider
403+ :: forall a
404+ . ReactContext a
405+ -> ReactComponent { value :: a , children :: Array JSX }
406+
407+ foreign import contextConsumer
408+ :: forall a
409+ . ReactContext a
410+ -> ReactComponent { children :: a -> Array JSX }
402411
403412-- | Create a provider `JSX` given a context value and children.
404413-- |
405414-- | __*See also:* `createContext`, `consumer`__
406415provider :: forall a . ReactContext a -> a -> Array JSX -> JSX
407416provider context value children =
408- element context.provider { value, children }
417+ element (contextProvider context) { value, children }
409418
410419-- | Create a consumer `JSX` from a context value to children.
411420-- |
412421-- | __*See also:* `createContext`, `producer`__
413422consumer :: forall a . ReactContext a -> (a -> Array JSX ) -> JSX
414423consumer context children =
415- element context.consumer { children }
424+ element (contextConsumer context) { children }
416425
417426-- |
418427-- | Internal utility or FFI functions
0 commit comments