我需要点击两次按钮来更新状态。
我发现了一些与此相关的问题,但对我没有帮助。
请查找以下代码。
import React,{useState} from "react";
import { BrowserRouter as Router, NavLink } from "react-router-dom";
import './SectionConnect.css';
const SectionConnect = () => {
const [activeButton, setActiveButton] = useState("company");
function toggleButton() {
setActiveButton(activeButton==="company" ? "individual" : "company");
}
return (
How it works
{activeButton==="company"?
We help your employees maximise potential through a bespoke, science-backed wellbeing platform.
We connect you with the very best practitioners and most effective
methods to achieve optimal health.
to="/"
exact
activeClassName="active-btn"
className="disable-btn"
onClick={toggleButton}
>
For companies
to="/forIndividuals"
exact
activeClassName="active-btn"
className="disable-btn"
onClick={toggleButton}
>
For individuals
);
};
export default SectionConnect
我不明白我哪里做错了。
提前谢谢!