gpt4 book ai didi

javascript - 创建 3 个额外组件来渲染组件信息

转载 作者:行者123 更新时间:2023-12-02 23:03:32 25 4
gpt4 key购买 nike

我正在完成在线类(class),并遇到了一个看似简单但无法解决的问题。我正在尝试重构内容组件,以便它本身不会呈现任何部分名称或其练习数量。 const 数据位于 APP 组件中,但我不确定如何从 Part 组件访问它而不将 const 数据放入 Content 组件中,这是错误的。

const Part1 = props => (
<p>
{props.part1} {props.exercises1}
</p>
);

const Part2 = props => (
<p>
{props.part2} {props.exercises2}
</p>
);

const Part3 = props => (
<p>
{props.part3} {props.exercises3}
</p>
);
const Content = props => {
return (
<div>
<Part1 />
<Part2 />
<Part3 />
</div>
);
};

const App = () => {
const course = "Half Stack application development";
const part1 = "Fundamentals of React";
const exercises1 = 10;
const part2 = "Using props to pass data";
const exercises2 = 7;
const part3 = "State of a component";
const exercises3 = 14;

return (
<div>
<Content
part1={part1}
exercises1={exercises1}
part2={part2}
exercises2={exercises2}
part3={part3}
exercises3={exercises3}
/>
</div>
);
};

现在我的输出中没有任何内容

最佳答案

你需要再次传递props,

<div>
<Part1 part1={props.part1} exercises1={props.exercises1} />
<Part2 part2={props.part2} exercises2={props.exercises2} />
<Part3 part3={props.part3} exercises3={props.exercises3} />
</div>

关于javascript - 创建 3 个额外组件来渲染组件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57696948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com