import React, { useState, useRef } from "react";
import { Link, animateScroll as scroll } from "react-scroll";
function Acc(props) {
const content = useRef(null);
const [setActive, setActiveState] = useState("");
const [setScroll, setScrollState] = useState();
function toggle() {
setActiveState(setActive === "" ? "active" : "");
setScrollState(setScroll === "active" ? <Link to={id} smooth={true} duration={500} spy={true} exact={true}></Link> : );
}
return (
<div className="a1" id={props.id}>
<div className="a2">
<div className="a3">
<button className="button" onClick={toggle}>
//image goes here
</button>
</div>
</div>
</div>
);
}
export default Acc;
为什么我会收到此错误?
./src/components/Acc.js
SyntaxError: /Users/me/Desktop/School/aapp/src/components/Acc.js: Unexpected token (24:121)
23 | setRotateState(setActive === "active" ? "icon" : "icon rotate");
> 24 | setScrollState(setScroll === "active" ? <Link to={id} smooth={true} duration={500} spy={true} exact={true}></Link> : );
| ^
25 | }
26 |
27 | return (
我如何解决它?id
目的是在单击按钮时为必要的 div(classname='a1' 有一个 )创建平滑的滚动动作。按钮必须平滑滚动以及触发toggle()
。
任何帮助将不胜感激 !