File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ module React
43
43
44
44
, getProps
45
45
, getRefs
46
+ , readRef
46
47
, getChildren
47
48
48
49
, readState
@@ -65,7 +66,11 @@ module React
65
66
) where
66
67
67
68
import Prelude
69
+
68
70
import Control.Monad.Eff (kind Effect , Eff )
71
+ import DOM.Node.Types (Node , readNode )
72
+ import Data.Foreign (F , Foreign , toForeign )
73
+ import Data.Foreign.Index (readProp )
69
74
import Unsafe.Coerce (unsafeCoerce )
70
75
71
76
-- | Name of a tag.
@@ -294,6 +299,16 @@ foreign import getRefs :: forall props state access eff.
294
299
ReactThis props state ->
295
300
Eff (refs :: ReactRefs (read :: Read | access ) | eff ) Refs
296
301
302
+ -- | Read named ref from Refs
303
+ readRef :: forall access eff .
304
+ String ->
305
+ Refs ->
306
+ Eff (refs :: ReactRefs (read :: Read | access ) | eff ) (F Node )
307
+ readRef name refs = pure $ join (readNode <$> prop)
308
+ where
309
+ prop :: F Foreign
310
+ prop = readProp name (toForeign refs)
311
+
297
312
-- | Read the component children property.
298
313
foreign import getChildren :: forall props state eff .
299
314
ReactThis props state ->
Original file line number Diff line number Diff line change @@ -297,6 +297,9 @@ radioGroup = unsafeMkProps "radioGroup"
297
297
readOnly :: Boolean -> Props
298
298
readOnly = unsafeMkProps " readOnly"
299
299
300
+ ref :: String -> Props
301
+ ref = unsafeMkProps " ref"
302
+
300
303
rel :: String -> Props
301
304
rel = unsafeMkProps " rel"
302
305
You can’t perform that action at this time.
0 commit comments