Ad

Element Type Is Invalid: Expected A String (for Built-in Components) Or A Class/function (for Composite Components) But Got: Symbol

- 1 answer

I'm trying to use lazy Loading for my app.

index.js

import React, { Suspense , lazy , Component } from 'react';
import ReactDOM from 'react-dom';
import 'index.scss';
import SomeComponent from './someComponent.js';
import * as serviceWorker from 'serviceWorker';

ReactDOM.render(<SomeComponent />, document.getElementById('root'));
serviceWorker.unregister();

some component index.js file

import React, { Suspense , lazy , Component } from 'react';
import { BrowserRouter } from 'react-router-dom';
const Header = lazy(() => import('./_header'));

class SomeComponent extends Component {
  render() {
    return (
      <BrowserRouter>
          <React.Fragment>
            <Suspense>
              <Header />
            </Suspense>
          </React.Fragment>
      </BrowserRouter>
    );
  }
}

export default SomeComponent;

header index.js file

import React, { Component } from 'react';
import './index.scss';

class Header extends Component {
    render() {
        return (
            <h1>Header</h1>
        );
    }
}
export default Header;

But I've got this error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: symbol.

My react version is v16.6.3.

Ad

Answer

Suspense and lazy are reachable in the following versions :

"react": "^16.6.3"
"react-dom": "^16.6.3"

This error relates to the react-dom which was not upgraded correctly!

Ad
source: stackoverflow.com
Ad