我嘗試將 a childrenand傳遞props給我的組件,孩子們傳遞得很好,但是道具就像未定義的一樣,我不明白為什么。當我不使用 children 時,效果很好。一個小片段來理解這個問題。 the functionimport React from "react";export function PropsChildren({ children }, props) { console.log("info props", props.name, props.age); return ( <div> <p>Props name is {props.name}</p> <p>Props age is {props.age}</p> </div> );}the callimport React from "react";import ReactDOM from "react-dom";import "./index.css";//import App from './App';import reportWebVitals from "./reportWebVitals";import { PropsChildren } from "./props/props_children";ReactDOM.render( <React.StrictMode> <PropsChildren name="Knupel" age={46}> {document} </PropsChildren> </React.StrictMode>, document.getElementById("root"));控制臺返回 info props undefined undefined
當孩子也經過時,道具看起來像未定義
GCT1015
2023-06-15 16:23:15