我对反应还很陌生,我正在玩一个非常简单的网站,它从 pokemon api 获取数据。

我想在我的列表项上添加一个 onClick 事件,以在单击时更改 css。但是当我像这样将 setExpand(!expand) 添加到我的列表项时,<Li onClick={setExpand(!expand)}>我收到一个错误,告诉我“错误:重新渲染次数太多。React 限制渲染数量以防止无限循环”,我无法理解。
//Styling
const Section = styled.section`
margin-top: 100px;
`;
const Ul = styled.ul`
margin:0;
padding:0;
list-style:none;
display: flex;
justify-content: center;
flex-wrap: wrap;
`;
const Main = styled.main`
max-width: 1200px;
margin: 0 auto;
width: 100%;
`;
export default function Test() {
//States
const [pokemonArray, newPokemon] = useState([]);
//Hooks
useEffect(() => {
(async () => {
const dataArray = [];
for (let i = 1; i < 6; …Run Code Online (Sandbox Code Playgroud)