如何更改类型或React Component?

时间:2019-10-31 18:30:04

标签: reactjs typescript

我试图有条件地包装一些组件:

class innerComponent extends React.Component{
  //...
}

class oldContainer extends React.Component{
  //...
}

class newContainer extends React.Component{
  //...
}

interface Props = {
  newContainer: boolean;
}

const Component: React.SFC<Props> = props => {
  container = React.Component;
  if (props.newContainer) {
    container = newContainer;
  } else {
    container = oldContainer;
  }
  return (
    <container>
      <innerComponent/>
    </container>
  )
};

也就是说,我需要能够更改组件的类型并在以后使用它。在React中有可能吗?如果是,该如何实现?

0 个答案:

没有答案