我尝试将 a childrenand传递props给我的组件,孩子们传递得很好,但是道具就像未定义的一样,我不明白为什么。当我不使用 children 时,效果很好。一个小片段来理解这个问题。 the function
import 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 call
import 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
泛舟湖上清波郎朗
相关分类