#reactjs
#reactjs
Вопрос:
Я следую этому руководству по react и получаю, что ReactDOM не определен:
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);
Я видел другой пост, но я все еще не могу заставить его работать. Я начинаю работать в react, и я хотел бы понять, почему я получаю приведенную ниже ошибку:
Комментарии:
1. в сообщении об ошибке говорится: «Ищите ключевые слова, чтобы узнать больше о каждой ошибке». ты это сделал?
2. В каком файле вы находитесь?
3. Я нахожусь в index.js
4. не знаю, почему вы так усложняете это, вы могли бы создать компонент под названием App внутри app.js файл и импортируйте это в index.js и делайте все, что вы хотите, в компоненте приложения
5. Пожалуйста, соблюдайте элементарную здравомыслие и правильно прочитайте ошибки, прежде чем добавлять новые вопросы
Ответ №1:
Вы забыли импортировать ReactDOM
import { render as renderJSX,ReactDom } from 'react-dom';