aleclarson aleclarson - 2 months ago 12
React JSX Question

How can I get a ReactElement from a tag?

The

PanResponder
methods are passed a
ResponderSyntheticEvent
whose
nativeEvent.target
is a React tag (which is just a
Number
). This is the same tag that is returned by
findNodeHandle
.

Is there a way to get the
ReactElement
from the React tag?

Edit:

I can use
ReactNativeTagHandles.tagToRootNodeID[tag]
to get the "root node ID". Now how can I get a
ReactElement
from that?

Answer
var ReactNativeComponentTree = require('ReactNativeComponentTree');

var reactInstance = ReactNativeComponentTree.getInstanceFromNode(reactTag);

This is only available in versions of facebook/react >= 15.0.2

You can see ReactNativeComponentTree defined here.