Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_reactDom2.default.render is not a function

Tags:

reactjs

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"] } 
like image 309
Sal-laS Avatar asked Apr 02 '16 16:04

Sal-laS


People also ask

Why ReactDOM Render is not working?

Use createRoot instead" occurs because the ReactDOM. render method has been deprecated. To solve the error, create a root element and use the ReactDOMClient.

How do I import createRoot into React?

import React from 'react'; import ReactDOM from 'react-dom'; import { createRoot } from 'react-dom/client'; import Switch from './components/Switch'; const root = ReactDOM. createRoot(document. getElementById('root')); root. render( <React.

What is ReactDOM createRoot?

createRoot(container[, options]); Create a React root for the supplied container and return the root. The root can be used to render a React element into the DOM with render : const root = createRoot(container); root.


1 Answers

You can change something in your Maincontainner component.

  1. Add it top: import ReactDOM from 'react-dom';
  2. Change render to ReactDOM.render
like image 67
VvV Avatar answered Sep 18 '22 12:09

VvV