React Native等效于React.createElement

时间:2015-11-12 10:27:04

标签: javascript reactjs react-native

在查看React时,特别是React (Virtual) DOM terminology我想知道是否有React Native的等价物,或者更确切地说,如何修改它以用于Native?

我想撰写一个视图,它由<Text> <TouchableHighlight> <TouchableHighlight>组成。两个<TouchableHighlight>元素将递增和递减计数器(<Text>标签)。

我是否有办法将这些参数传递给类似于React.createElement的函数,该函数将返回包含这些元素的视图?

1 个答案:

答案 0 :(得分:9)

createElement is also available on React Native. So you can do:

var textElem = React.createElement(Text, [], ['Hello world']);

You must supply a ReactClass as first parameter, strings are not allowed as the first parameter in React Native since those are meant to be used for html tags in regular React.