1

I have use case to render component from database. In data base they are stored as string format like below:

let Sample = `({firstName})=><h1>My name is {firstName}</h1>`;

When I try to render this in react, it shows as string. How to render string type of functional component.

class App extends Component {

  this.state = {
  "sathish" : "firstName",
  }

  render (){
      // how do it use string of functional component like below
      return <Sample firstName={this.state.firstName} />
   }
}
Zobia Kanwal
  • 4,085
  • 4
  • 15
  • 38
sathish kumar
  • 1,477
  • 1
  • 11
  • 18

1 Answers1

-1

you can use eval for this: let Sample = eval(({firstName})=><h1>My name is {firstName}</h1>);

or more complicate solution it's https://babeljs.io/docs/en/babel-parser#example

Vadim Hulevich
  • 1,803
  • 8
  • 17