@@ -23,6 +23,8 @@ module React.Basic
23
23
, Ref
24
24
, ReactContext
25
25
, createContext
26
+ , contextConsumer
27
+ , contextProvider
26
28
, provider
27
29
, consumer
28
30
) where
@@ -373,14 +375,11 @@ foreign import toReactComponent
373
375
-> { render :: Self props state -> JSX | spec }
374
376
-> ReactComponent { | jsProps }
375
377
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
380
379
381
380
-- | 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.
384
383
-- |
385
384
-- | ```purs
386
385
-- | render self =
@@ -398,21 +397,31 @@ type ReactContext a =
398
397
-- | ```
399
398
-- |
400
399
-- | __*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 }
402
411
403
412
-- | Create a provider `JSX` given a context value and children.
404
413
-- |
405
414
-- | __*See also:* `createContext`, `consumer`__
406
415
provider :: forall a . ReactContext a -> a -> Array JSX -> JSX
407
416
provider context value children =
408
- element context.provider { value, children }
417
+ element (contextProvider context) { value, children }
409
418
410
419
-- | Create a consumer `JSX` from a context value to children.
411
420
-- |
412
421
-- | __*See also:* `createContext`, `producer`__
413
422
consumer :: forall a . ReactContext a -> (a -> Array JSX ) -> JSX
414
423
consumer context children =
415
- element context.consumer { children }
424
+ element (contextConsumer context) { children }
416
425
417
426
-- |
418
427
-- | Internal utility or FFI functions
0 commit comments