【发布时间】:2021-06-24 21:41:13
【问题描述】:
我按照here 发现的无效钩子警告无济于事。我在代码中忽略了一些错误。当我使用命令 npm ls react-dom 我得到:“react-dom@17.0.2”。我的代码有什么问题?我认为您可以像下面那样在功能组件中使用 useState 钩子
import {useState} from 'react';
import ReactDOM from 'react-dom';
import './index.css';
function Navbar()
{
const [childFontSize, setChildFontSize] = useState("5vh");
return(
<div id={"navbarContainer"}>
<span className={"font"}>XYZ</span>
<span className={"font"} style={{fontSize: childFontSize}}>XYZ</span>
<span className={"font"} style={{fontSize: childFontSize}}>XYZ</span>
<span className={"font"} style={{fontSize: childFontSize}}>XYZ</span>
</div>
);
}
ReactDOM.render(Navbar(), document.getElementById("navbar"));
【问题讨论】:
-
这是用于浏览器的 React 还是 React Native? ReactDOM 仅用于浏览器,但您添加了
react-native标签
标签: javascript reactjs react-native react-hooks