简体   繁体   English

ReactDom 已声明但其值从未被读取

[英]ReactDom is declared but its value is never read

I am just starting to learn react and I am trying this code:我刚开始学习反应,我正在尝试这段代码:

import React from 'react';
import ReactDom from 'react-dom';

const element = <h1>Hello world</h1>;
console.log(element);

But I have error:但我有错误:

ReactDom is declared but its value is never read ReactDom 已声明但其值从未被读取在此处输入图像描述 what may cause this error please?请问什么可能导致这个错误?

On line two you declare ReactDom (and assign (ie write ) the imported value from the react-dom module to it).在第二行,您声明ReactDom (并分配(即写入)从 react-dom 模块导入的值给它)。

 import ReactDom from 'react-dom';

… and then you never do anything with it (ie you don't read the value back out of the ReactDom variable). ......然后你永远不会对它做任何事情(即你不会从ReactDom变量中读取值)。

Normally in a React application you would use ReactDom to insert a component into the DOM, but here you just console.log the result of evaluating some JSX instead.通常在 React 应用程序中,您会使用ReactDom将组件插入到 DOM 中,但在这里您只是console.log评估一些 JSX 的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM