Вставка имени компонента в виде строки переменной - PullRequest
0 голосов
/ 24 марта 2020

В моих данных у меня есть поле, которое содержит значение "TableTwoColum". «TableTwoColum» - это имя компонента, который я sh должен вызвать в родительском компоненте. Кажется, переменная отображается на странице в виде текста, а не кода html.

CODE

import React, { Fragment } from 'react';
// import TableTwoColum from '../molecules/table-two-column';
import Test from '../molecules/test-component'



export default function(props) {
  const ComponentName = props.data[0].tableType;
  const componentString = "<"+ ComponentName +"bookFormat={props.bookFormat} data={props.data}"

  return (
    <section id={props.sectionName} className={'padding-3 page-size-'+props.bookFormat}>
    {props.data[0].article}
    {componentString}       

  </section>
  );
}
import React, { Fragment } from 'react';
// import TableTwoColum from '../molecules/table-two-column';
import Test from '../molecules/test-component'



export default function(props) {
  const ComponentName = props.data[0].tableType;
  const componentString = "<"+ ComponentName +"bookFormat={props.bookFormat} data={props.data}"

  return (
    <section id={props.sectionName} className={'padding-3 page-size-'+props.bookFormat}>
    {props.data[0].article}
    {componentString}       

  </section>
  );
}

ЧТО Я ПОПРОБОВАЛ Я попытался `` const componentString = {"< "+ ComponentName +" bookFormat = {props.bookFormat} data = {props.data} "}

this does not compile "ine 9:30:  Parsing error: Unexpected token"

const componentString = (" <"+ ComponentName +" bookFormat = {props.bookFormat} data = {props.data} ") </p>

this still escapes as text

...