這段代碼有效,但我不禁認為有更好的方法。我無法將 expanded 設置為 false,因為當我這樣做時組件會中斷(就像他們在Set JSX attribute based on another JSX attribute react中所做的那樣)另外,我需要添加更多條件分支,這意味著代碼重復if (itemProps.Expanded == true) { return ( <Accordion expanded={true}> ... </Accordion > )}else { return ( <Accordion> ... </ Accordion> )}有什么建議么?
React JSX 選擇性地將屬性傳遞給組件
交互式愛情
2023-03-10 13:41:29