Reactjs 如何将包含Jsx本机代码的字符串作为Render()中的代码进行求值?
我有一些存储在状态中的变量,其中包含要在React Native中呈现的代码,如:Reactjs 如何将包含Jsx本机代码的字符串作为Render()中的代码进行求值?,reactjs,react-native,parsing,eval,jsx,Reactjs,React Native,Parsing,Eval,Jsx,我有一些存储在状态中的变量,其中包含要在React Native中呈现的代码,如: JsxToRender = "<View> <Text h1 style={styles.h1}>Titre 1</Text> <Image source={{ uri:file:///data/data/com.app/avatar.jpg }} style={styles.Image} /> </View>" 如何将这些字符串解析为代码?我尝试了
JsxToRender = "<View> <Text h1 style={styles.h1}>Titre 1</Text>
<Image source={{ uri:file:///data/data/com.app/avatar.jpg }}
style={styles.Image} /> </View>"
如何将这些字符串解析为代码?我尝试了
eval()
,但没有成功。请更改此行
JsxToRender = "<View> <Text h1 style={styles.h1}>Titre 1</Text>
JsxToRender=“Titre 1
到
JsxToRender=“{Titre}1
现在就使用它。这能回答您的问题吗?谢谢,但在我的例子中,它不是Html,而是jsx。谢谢,但这不是问题,所有变量“jsxToRender”都是字符串。另一个例子是变量test=“Hi,I'm valentin”,它是从API获取的字符串。我只想在渲染中返回这个。问题是变量的类型是字符串。
JsxToRender = "<View> <Text h1 style={styles.h1}>Titre 1</Text>
JsxToRender = "<View> <Text h1 style={styles.h1}>{Titre} 1</Text>