Deepak
Deepak

Reputation: 41

How to render jsx stored as a string in ReactJS

I am trying to build a react app with customized components. The input to the app is a jsx(as a string) coming from an API. Now i want to render this input jsx (a string variable), but not able to do that. I have tried eval() and dangerouslySetInnerHTML options, but it did not work out. My JSX String looks like

'<div> <MyComponent attr_1={this.state.array["field"]}></MyComponent> </div>'

Upvotes: 2

Views: 1523

Answers (1)

Deepak
Deepak

Reputation: 41

Hi I figured out JsxParser is the right way of solving my problem. react-jsx-parser provides capability to parser and render react component from JSX string.

Upvotes: 2

Related Questions