File tree 4 files changed +75
-11
lines changed
4 files changed +75
-11
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,6 @@ module React
32
32
, pureComponentWithDerivedState
33
33
, statelessComponent
34
34
, ReactClass
35
- , ReactRef
36
35
, getProps
37
36
, getState
38
37
, setState
@@ -68,11 +67,11 @@ module React
68
67
69
68
import Prelude
70
69
71
- import Data.Nullable (Nullable )
72
70
import Effect (Effect )
73
71
import Effect.Exception (Error )
74
72
import Effect.Uncurried (EffectFn1 )
75
73
import Prim.Row as Row
74
+ import React.Ref as Ref
76
75
import Type.Row (type (+))
77
76
import Unsafe.Coerce (unsafeCoerce )
78
77
@@ -252,10 +251,6 @@ foreign import data ReactClass :: Type -> Type
252
251
253
252
foreign import fragment :: ReactClass { children :: Children }
254
253
255
- -- | Type for React refs. This type is opaque, but you can use `Data.Foreign`
256
- -- | and `DOM` to validate the underlying representation.
257
- foreign import data ReactRef :: Type
258
-
259
254
-- | Read the component props.
260
255
foreign import getProps :: forall props state .
261
256
ReactThis props state ->
@@ -340,7 +335,7 @@ class ReactPropFields (required :: # Type) (given :: # Type)
340
335
341
336
type ReservedReactPropFields r =
342
337
( key :: String
343
- , ref :: SyntheticEventHandler ( Nullable ReactRef )
338
+ , ref :: Ref.RefHandler Ref.ReactInstance
344
339
| r
345
340
)
346
341
Original file line number Diff line number Diff line change @@ -2,10 +2,9 @@ module React.DOM.Props where
2
2
3
3
import Prelude
4
4
5
- import Data.Nullable (Nullable )
6
5
import Effect (Effect )
7
6
import Effect.Uncurried (mkEffectFn1 )
8
- import React ( ReactRef )
7
+ import React.Ref as Ref
9
8
import React.SyntheticEvent
10
9
( SyntheticEvent
11
10
, SyntheticAnimationEvent
@@ -894,8 +893,8 @@ onScrollCapture f = unsafeMkProps "onScrollCapture" (mkEffectFn1 f)
894
893
onWheelCapture :: (SyntheticWheelEvent -> Effect Unit ) -> Props
895
894
onWheelCapture f = unsafeMkProps " onWheelCapture" (mkEffectFn1 f)
896
895
897
- ref :: ( Nullable ReactRef -> Effect Unit ) -> Props
898
- ref f = unsafeMkProps " ref" (mkEffectFn1 f)
896
+ ref :: Ref.RefHandler Ref.NativeNode -> Props
897
+ ref = unsafeMkProps " ref"
899
898
900
899
suppressContentEditableWarning :: Boolean -> Props
901
900
suppressContentEditableWarning = unsafeMkProps " suppressContentEditableWarning"
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ var React = require ( "react" ) ;
4
+
5
+ exports . createRef = React . createRef ;
6
+
7
+ exports . liftCallbackRef = function ( ref ) {
8
+ return { current : ref } ;
9
+ }
10
+
11
+ exports . getCurrentRef_ = function ( ref ) {
12
+ return ref . current ;
13
+ }
Original file line number Diff line number Diff line change
1
+ module React.Ref
2
+ ( Ref
3
+ , RefHandler
4
+ , ReactInstance
5
+ , NativeNode
6
+ , fromRef
7
+ , fromEffect
8
+ , getCurrentRef
9
+ , createNodeRef
10
+ , createInstanceRef
11
+ ) where
12
+
13
+ import Prelude
14
+ import Effect (Effect )
15
+ import Data.Maybe (Maybe )
16
+ import Data.Nullable (Nullable )
17
+ import Data.Nullable as Nullable
18
+ import Effect.Uncurried (EffectFn1 , runEffectFn1 , mkEffectFn1 )
19
+ import Unsafe.Coerce (unsafeCoerce )
20
+
21
+ -- - | An instance of a React class.
22
+ foreign import data ReactInstance :: Type
23
+
24
+ -- - | A platform-specific native layout node. On the web this will be a DOM
25
+ -- - | element (see `Web.HTML.HTMLElement`).
26
+ foreign import data NativeNode :: Type
27
+
28
+ foreign import data Ref :: Type -> Type
29
+
30
+ foreign import data RefHandler :: Type -> Type
31
+
32
+
33
+ foreign import createRef :: forall a . Effect (Ref a )
34
+
35
+ foreign import liftCallbackRef :: forall a . Ref a -> Ref a
36
+
37
+
38
+ createNodeRef :: Effect (Ref NativeNode )
39
+ createNodeRef = createRef
40
+
41
+
42
+ createInstanceRef :: Effect (Ref ReactInstance )
43
+ createInstanceRef = createRef
44
+
45
+
46
+ fromRef :: forall a . Ref a -> RefHandler a
47
+ fromRef = unsafeCoerce
48
+
49
+
50
+ fromEffect :: forall a . (Ref a -> Effect Unit ) -> RefHandler a
51
+ fromEffect f = unsafeCoerce $ mkEffectFn1 (f <<< liftCallbackRef)
52
+
53
+
54
+ foreign import getCurrentRef_ :: forall a . EffectFn1 (Ref a ) (Nullable a )
55
+
56
+ getCurrentRef :: forall a . Ref a -> Effect (Maybe a )
57
+ getCurrentRef ref = Nullable .toMaybe <$> runEffectFn1 getCurrentRef_ ref
You can’t perform that action at this time.
0 commit comments