Javascript 为什么不是';子组件是否已渲染?
我在APP.js组件中编写了以下代码:Javascript 为什么不是';子组件是否已渲染?,javascript,html,reactjs,react-native,jsx,Javascript,Html,Reactjs,React Native,Jsx,我在APP.js组件中编写了以下代码: import React from "react"; import Exam from "./exam.js"; export default function App() { return ( <Exam> <h1>hashemi</h1> </Exam> ); } import React from "react"; const Exam = ({
import React from "react";
import Exam from "./exam.js";
export default function App() {
return (
<Exam>
<h1>hashemi</h1>
</Exam>
);
}
import React from "react";
const Exam = ({child}) => {
return (
<div>
<p>parastoo</p>
{child}
</div>
);
};
export default Exam;
从“React”导入React;
从“/Exam.js”导入考试;
导出默认函数App(){
返回(
哈什米
);
}
我在exam.js组件中编写了以下代码:
import React from "react";
import Exam from "./exam.js";
export default function App() {
return (
<Exam>
<h1>hashemi</h1>
</Exam>
);
}
import React from "react";
const Exam = ({child}) => {
return (
<div>
<p>parastoo</p>
{child}
</div>
);
};
export default Exam;
从“React”导入React;
常量检查=({child})=>{
返回(
帕拉索
{child}
);
};
导出默认检查;
但结果表明:
帕拉索
有什么问题?为什么子级
不呈现?子组件通过子级
道具传递到组件,即使只有一个子组件:
const Exam = ({children}) => {
return (
<div>
<p>parastoo</p>
{children}
</div>
);
};
const-Exam=({children})=>{
返回(
帕拉索
{儿童}
);
};
它被称为道具。儿童
。请阅读文档部分
const考试=(道具)=>{
返回(
帕拉索
{props.children}
);
};
我希望这有帮助 在React中,您可以将道具或属性传递给子组件。假设您有一个应用程序组件,它呈现一个名为CurrentDate的子组件,该子组件是一个无状态功能组件。您可以通过以下方式向CurrentDate传递日期属性:
const CurrentDate = (props) => {
return (
<div>
{ /* change code below this line */ }
<p>The current date is: {props.date} </p>
{ /* change code above this line */ }
</div>
);
};
const CurrentDate=(道具)=>{
返回(
{/*更改此行下方的代码*/}
当前日期为:{props.date}
{/*更改此行上方的代码*/}
);
};
日历是一个父组件,您可以通过写入来向日历传递日期属性
class Calendar extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h3>What date is it?</h3>
{ /* change code below this line */ }
<CurrentDate date={Date()}/>
{ /* change code above this line */ }
</div>
);
}
};
类日历扩展React.Component{
建造师(道具){
超级(道具);
}
render(){
返回(
今天是几号?
{/*更改此行下方的代码*/}
{/*更改此行上方的代码*/}
);
}
};