1

I'm new to React thus the question. I'm trying to render a basic React component. This is my index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>React</title>
  </head>
  <body>

    <div id="root"></div>
    <script src="/bundle.js"></script>
  </body>
</html>

This is my index.js

import React from 'react';
import 'babel-polyfill';
import { render } from 'react-dom';
import './styles/style.css';
import  '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import Layout from './components/Layout';

React.render(<Layout />, document.getElementById("root"));

This is my Layout component.

import React from 'react';
import {render } from 'react-dom';

class Layout extends React.Component{
  render(){
    return(
      <div className="container-fluid">
        <div className="jumbotron">
          <h1>This is home now</h1>
        </div>
      </div>
    );
  }
}
export default Layout;

This is the error I see on the console,

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

When I start the dev server, I see a blank page with nothing getting rendered. Any help appreciated.

6
  • Do you see anything in console when you load the page? warnings/errors Commented Oct 26, 2016 at 21:12
  • 1
    render(<Layout />, document.getElementById("root")); Commented Oct 26, 2016 at 21:12
  • What are you using this bundle this js? Commented Oct 26, 2016 at 21:13
  • 2
    You've got them mixed up - ReactDOM.render not React.render Commented Oct 26, 2016 at 21:13
  • Updated question with console output. Commented Oct 26, 2016 at 21:14

1 Answer 1

2

The way you import the render function inside index.js from react-dom changes the way you invoke it.

import { render } from 'react-dom';

Here you just import the render method from the react-dom object. So to use it you would say

render(<Layout />, document.getElementById("root"));
Sign up to request clarification or add additional context in comments.

3 Comments

I would recommend addressing the possible confusion. render inside the component is not ReactDOM.render, and is not used for actually rendering to DOM - that's what ReactDOM.render is for
@AndrewLi Im referring to the import in the index.js file. edited to specify
I understand that, but mention there is no need for the react-dom import in the component. It may be a source of confusion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.