When looking at React, specifically React (Virtual) DOM terminology I am wondering whether there is an equivalent for React Native, or rather, how this can be modified for use with Native?
I am wanting to compose a view, it consists of a <Text>
<TouchableHighlight>
<TouchableHighlight>
. The two <TouchableHighlight>
elements will increment and decrement a counter (the <Text>
label).
Is there a way I can perhaps pass these are parameters into a function similar to React.createElement
that will return a view with these elements in?
createElement()Create and return a new React element of the given type. The type argument can be either a tag name string (such as 'div' or 'span' ), a React component type (a class or a function), or a React fragment type. Code written with JSX will be converted to use React.createElement() .
createElement is the code that JSX gets compiled or converted into and is used by reacting to create elements. cloneElement is used for cloning elements and passing them new props. This method is used to describe how the User Interface looks. This method is used to manipulate the elements.
Explanation: The Babel is the tool used to turn into createElement calls also babel is a transpiler that is conversion.
React and React Native use JSX, a syntax that lets you write elements inside JavaScript like so: <Text>Hello, I am your cat! </Text> . The React docs have a comprehensive guide to JSX you can refer to learn even more. Because JSX is JavaScript, you can use variables inside it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With