2

I have some variables stored in state which contains code to render in React Native, like:

JsxToRender = "<View> <Text h1 style={styles.h1}>Titre 1</Text> 
<Image source={{ uri:file:///data/data/com.app/avatar.jpg }}
style={styles.Image} /> </View>"

I need to return them in render() like this:

render() {
return (this.state.JsxToRender) }

How can I parse this strings into code? I tried with eval() in vain.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
valentin
  • 41
  • 2
  • Does this answer your question? [Render HTML string as real HTML in a React component](https://stackoverflow.com/questions/39758136/render-html-string-as-real-html-in-a-react-component) – norbitrial Dec 14 '19 at 16:46
  • thanks, but in my case it's not Html but it's already jsx. – valentin Dec 15 '19 at 20:16

1 Answers1

-2

Kindly change this line

JsxToRender = "<View> <Text h1 style={styles.h1}>Titre 1</Text> 

to

JsxToRender = "<View> <Text h1 style={styles.h1}>{Titre} 1</Text> 

and use it now.

Avinash Dalvi
  • 8,551
  • 7
  • 27
  • 53
  • 1
    Thanks but it's not the problem, all the variable "jsxToRender" is a string. An other exemple, I have the variable test = " Hi, I'm valentin" wich is a string fetch from an API. I just want to return this in render. The probleme is the type of variable is String. – valentin Dec 14 '19 at 18:45