import React, { Component } from 'react';
let SomeComp;
if (process.env.REACT_APP_V === '1') {
SomeComp = import('../section/SomeComp');
}
Class App
...
render() {
return {
{this.state.version === '1' && <SomeComp />}
}
}
I want to import the SomeComp component conditionally.
Is this the correct way?
The error I'm getting is:
Warning: React.createElement: type is invalid -- expected a string (for built-in components)
If I do a normal
import SomeComp from '../section/SomeComp';
it works. So it's no issue with the export from SomeComp
Any ideas?
import()is async (it returns a promise) so you cannot render it until it's loaded.