Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
97 views
in Technique[技术] by (71.8m points)

reactjs - _reactDom2.default.render is not a function

consider the following react code

the main.js file is:

import React from 'react';
import ReactDOM from 'react-dom';
import Maincontainner from './maincontainner';

ReactDOM.render(
    <div>
        <h1>News</h1>
        <Maincontainner/>
    </div>,
    document.getElementById('content')
);

and the component is:

import React from 'react';


export default class  Maincontainner extends React.Component{

    render() {
        console.log("I am here");
        return (<dev> Salman is here </dev>);
    }
}

the problem is, when i run the application, i face with following error in my console:

Uncaught TypeError: _reactDom2.default.render is not a function

and here is the dependencies

"dependencies": {
    "webpack": "^1.12.14",
    "webpack-dev-server": "^1.14.1",
    "react" : "^0.14.7",
    "react-dom" : "^0.14.7",
    "babel-cli": "^6.5.1",
    "babel-preset-es2015": "^6.5.0",
    "babel-loader": "^6.2.1",
    "babel-preset-react": "^6.3.13",
    "babelify": "^7.2.0"


  }

Update: webpack.config.json

module.exports={

    entry: './js/main.js',
    output:{

        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /.js?$/,
                loader: 'babel',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015', 'react']
                }
            }
        ]
    },
    devServer:{


        port:3000
    }





};

I have also 1 .babelrc file

{
  "presets": ["es2015", "react"]
}
question from:https://stackoverflow.com/questions/36376146/reactdom2-default-render-is-not-a-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can change something in your Maincontainner component.

  1. Add it top: import ReactDOM from 'react-dom';
  2. Change render to ReactDOM.render

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...