フロントエンジニア芸人もりたけんじのreact

【React】エラー「invariant.js:38Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `t`.」

【React】エラー「invariant.js:38Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `t`.」

このように怒られたら、


例えば、
一方で下の様にclassをexportして
export class FormComponent extends React.Component {
constructor(props){
super(props);
}
render() {
let countFn = function (n) {
return ;
};
let Array = immutable.Range(0, 10).toArray();
let ele = Array.map(countFn);
return (

{ele}

);
}
};

----------------
import側で
import React from 'react';
import ReactDOM from 'react-dom';
import FormComponent from './component/FormComponent';

export default class HelloReact extends React.Component {
constructor(props){
super(props);
}
render() {
return (

);
}
}
ReactDOM.render(
,
document.getElementById('content')
);

このように呼んでいたら出るエラーです。
export側で
export default class FormComponent extends React.Component {
とするか、
import側で
import { FormComponent } from './component/FormComponent';
このようにしてください。

つまりexportとimportの関係を確認してください
ありがとうございました。

【 併せて読みたい 】

【REACT】REACTの動きを理解したい人の為の最小サンプル

【REACT入門】過去のREACT初心者の自分にREACTのPROPSとSTATEの違いを簡単に説明してあげたい

【REACT × ES6 × FLUX】を手っ取り早く学びたい人の為にサンプル作ったよ【3の倍数と3が付くときだけ猫になるCOUNTER】

REACT × FLUX × ES6 [WIP]LINE風チャット

他のReact記事

フロントエンド記事

github

qiita