如果我嘗試使用Object.keys(children).length并且只有 1 個子組件,那么它會給我一個子組件所具有的鍵的數量。這種方法只有在有多個子組件時才有效。我如何找到一個組件的子組件數量?<Navbar> <Component 1/></Navbar>const Navbar = ({ children }) => { console.log(Object.keys(children).length); //displays properly only if more than 1 child component console.log(children.length); //undefined ...
React 如何知道父組件有多少個子組件?
牛魔王的故事
2023-01-06 11:19:55