Assume we have a flag
, no different from the state
or props
:
import ComponentOne from './ComponentOne';
import ComponentTwo from './ComponentTwo';
~~~
const Compo = flag ? ComponentOne : ComponentTwo;
~~~
<Compo someProp={someValue} />
With flag Compo
fill with one of ComponentOne
or ComponentTwo
and then the Compo
can act like a React Component.