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
375 views
in Technique[技术] by (71.8m points)

reactjs - React.js - 'ReactDOM' is not defined no-undef

I am following this tutorial on react and i am getting the reactDOM is not defined:

 import React from 'react';
 import { render as renderJSX } from 'react-dom';
 // The two components we're to passing props to
 // when they're rendered.
 import MyButton from './myButton';
 import MyClientList from './myClientList';
 const appState = {
        text: 'My Button',
        disabled: true,
        items: [
        'First',
        'Second',
        'Third', ],
      };
       // Defines our own "render()" function. The "renderJSX()"
        // function is from "react-dom" and does the actual
        // rendering. The reason we're creating our own "render()"
        // function is that it contains the JSX that we want to
        // render, and so we can call it whenever there's new
        // application data.
        function render(props) {
          renderJSX((
            <main>
              { /* The "MyButton" component relies on the "text"
                   and the "disabed" property. The "text" property
                   is a string while the "disabled" property is a
                   boolean. */ }
              <MyButton
                text={props.text}
                disabled={props.disabled}
              />
              { /* The "MyList" component relies on the "items"
                   property, which is an array. Any valid
                   JavaScript data can be passed as a property. */ }
              <MyClientList items={props.items} />
            </main>
           ),
            document.getElementById('app')
          );
// Performs the initial rendering...
        render(appState);
        // After 1 second, changes some application data, then
        // calls "render()" to re-render the entire structure.
        setTimeout(() => {
          appState.disabled = false;
          appState.items.push('Fourth');
          render(appState);
        }, 1000);

I have seen other post but I can still not get it to work. I am starting out in react and I would like to understand why i am getting the below error:

enter image description here

question from:https://stackoverflow.com/questions/65623169/react-js-reactdom-is-not-defined-no-undef

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

1 Answer

0 votes
by (71.8m points)

You forget to import ReactDom

 import { render as renderJSX,ReactDom } from 'react-dom';


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

...