我试图有条件地包装一些组件:
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中有可能吗?如果是,该如何实现?