-1

Error

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of

Switch.jsx

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import { SwitchUnit } from './sitch_unit.jsx';

export default class MySwitch extends Component{

  constructor(props) {
    super(props);

  }

  render(){
    return(<div>
        <SwitchUnit />
        <SwitchUnit />
        </div>
    );
  }
}

sitch_unit.jsx

import React, {Component} from 'react';
import ReactDOM from 'react-dom';

export default class SwitchUnit extends Component{

  constructor(props) {
    super(props);

  }

  render(){
    return(
        <div className="xxx">xxx</div>
    );
  }
}
mbarish-me
  • 897
  • 1
  • 14
  • 25

2 Answers2

2

You have exported SwitchUnit as default. Replace import { SwitchUnit } from './sitch_unit.jsx' to import SwitchUnit from './sitch_unit.jsx'

Lingaraju E V
  • 493
  • 2
  • 10
1

You must import like this:

import SwitchUnit from './sitch_unit.jsx';

because SwitchUnit is default method.

Emad Emami
  • 6,089
  • 3
  • 28
  • 38