Source:  Twitter logo

Index.js:

import React from 'react'; 
import buttonsInstance from 'components/button-instance';
import {ReactDOM} from 'react-dom';

ReactDOM.render(buttonsInstance, document.getElementById('app'));

and button-instance.js:

import React from 'react';
import {ButtonToolbar} from 'react-bootstrap';
import {Button} from 'react-bootstrap';

const buttonsInstance = (
  <div>
    <ButtonToolbar>
      <Button bsStyle="primary" bsSize="large">Large button</Button>
      <Button bsSize="large">Large button</Button>
    </ButtonToolbar>
    <ButtonToolbar>
      <Button bsStyle="primary">Default button</Button>
      <Button>Default button</Button>
    </ButtonToolbar>
    <ButtonToolbar>
      <Button bsStyle="primary" bsSize="small">Small button</Button>
      <Button bsSize="small">Small button</Button>
    </ButtonToolbar>
    <ButtonToolbar>
      <Button bsStyle="primary" bsSize="xsmall">Extra small button</Button>
      <Button bsSize="xsmall">Extra small button</Button>
    </ButtonToolbar>
  </div>
);

I'm trying to use reactbootstrap from https://react-bootstrap.github.io/components.html .

Then I got error :

Uncaught TypeError: Cannot read property 'render' of undefined
    at Object.<anonymous> (index.js:9)
    at __webpack_require__ (bootstrap 571b93c…:657)
    at fn (bootstrap 571b93c…:85)
    at Object.<anonymous> (log-apply-result.js:30)
    at __webpack_require__ (bootstrap 571b93c…:657)
    at module.exports (bootstrap 571b93c…:706)
    at bootstrap 571b93c…:706

I'm use webpack, webpack-dev-server and es6. My react and react-dom is up to date. I have no idea about how to fix this.

Import the ReactDOM like this:

import ReactDOM from 'react-dom';

Its a default import (import the complete package to use the different methods of that) not named import, that's why you are getting the error:

Cannot read property 'render' of undefined

Or you can directly import the render method from react-dom like this:

import {render} from 'react-dom';

now use render to directly render the component:

render(buttonsInstance, document.getElementById('app'));
23 users liked answer #0dislike answer #023
Mayank Shukla profile pic
Mayank Shukla

If you get the following error

Cannot read property xxx of undefined

And if you're using react-script-ts as well as rollup use import * as ...

import * as React from "react";
import * as ReactDOM from "react-dom";
1 users liked answer #1dislike answer #11
callmemath profile pic
callmemath

Make sure react version and react-dom versions are compatible.

Ex. For react version 16.9.0, use 'react-dom' version 16.9.0

0 users liked answer #2dislike answer #20
Yuvraj Patil profile pic
Yuvraj Patil

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).