'useState is not a function' React 部署什么都不显示
'useState is not a function' React deploy showing nothing
我已经尝试部署一个基本的 React 应用程序(仍处于早期阶段)。加载时分页 - 只显示背景,我在控制台中出现错误“.useState 不是函数”
以下是问题中标记的组件。这是开源代码的 link:https://github.com/mariaalouisaa/3-in-1-react
提前致谢!!
import "./Home.css";
import home from "./images/home.png";
import TimeAndDate from "./TimeAndDate";
import Todo from "./Todo";
import Stopwatch from "./Stopwatch";
import { useState } from "react/cjs/react.development";
export default function Home() {
const [dateVis, setsetDatevis] = useState(false);
const [todoVis, setsetTodovis] = useState(false);
const [stopVis, setsetStopvis] = useState(false);
function popUp(e) {
if (e.target.name === "date") setsetDatevis(true);
if (e.target.name === "todo") setsetTodovis(true);
if (e.target.name === "stop") setsetStopvis(true);
}
return (
<div>
<button
onClick={() => {
setsetDatevis(false);
setsetTodovis(false);
setsetStopvis(false);
}}
className="homebutton"
>
<img src={home} alt={home} />
</button>
<div className="Home">
<button name="date" onClick={popUp}>
Time + Date
</button>
<button name="todo" onClick={popUp}>
To-do {<br />}List
</button>
<button name="stop" onClick={popUp}>
Stop- watch
</button>
<TimeAndDate active={dateVis} />
<Todo active={todoVis} />
<Stopwatch active={stopVis} />
</div>
</div>
);
}
我认为你也应该导入 React
并按照 documentation:
中所说的正确方式导入 useState
import React, { useState } from 'react';
我已经尝试部署一个基本的 React 应用程序(仍处于早期阶段)。加载时分页 - 只显示背景,我在控制台中出现错误“.useState 不是函数”
以下是问题中标记的组件。这是开源代码的 link:https://github.com/mariaalouisaa/3-in-1-react
提前致谢!!
import "./Home.css";
import home from "./images/home.png";
import TimeAndDate from "./TimeAndDate";
import Todo from "./Todo";
import Stopwatch from "./Stopwatch";
import { useState } from "react/cjs/react.development";
export default function Home() {
const [dateVis, setsetDatevis] = useState(false);
const [todoVis, setsetTodovis] = useState(false);
const [stopVis, setsetStopvis] = useState(false);
function popUp(e) {
if (e.target.name === "date") setsetDatevis(true);
if (e.target.name === "todo") setsetTodovis(true);
if (e.target.name === "stop") setsetStopvis(true);
}
return (
<div>
<button
onClick={() => {
setsetDatevis(false);
setsetTodovis(false);
setsetStopvis(false);
}}
className="homebutton"
>
<img src={home} alt={home} />
</button>
<div className="Home">
<button name="date" onClick={popUp}>
Time + Date
</button>
<button name="todo" onClick={popUp}>
To-do {<br />}List
</button>
<button name="stop" onClick={popUp}>
Stop- watch
</button>
<TimeAndDate active={dateVis} />
<Todo active={todoVis} />
<Stopwatch active={stopVis} />
</div>
</div>
);
}
我认为你也应该导入 React
并按照 documentation:
useState
import React, { useState } from 'react';