如何从Next.js中的动态创建函数组件中获取值
我有一个组件数量。它改变了。我动态添加尽可能多的功能组件。 然后我想获取变量的值。
const MainComponent: React.FC<Props> = ({ fields, label, addCount }) => {
const components = () => {
const comps = [];
for (let index = 0; index < addCount; index++) {
comps.push(<CampaignConfigurationProperty fields={fields[index]} label={label}></CampaignConfigurationProperty>);
}
return comps;
};
return (
<div>
<p>{label}</p>
<div className={styles.anotherText + " " + styles.endText + " col"}>
{components()}
</div>
</div>
);
};
export default MainComponent;
I have a component count. It changes. I add dynamically function component as many as count.
Then I want to get values of variables.
const MainComponent: React.FC<Props> = ({ fields, label, addCount }) => {
const components = () => {
const comps = [];
for (let index = 0; index < addCount; index++) {
comps.push(<CampaignConfigurationProperty fields={fields[index]} label={label}></CampaignConfigurationProperty>);
}
return comps;
};
return (
<div>
<p>{label}</p>
<div className={styles.anotherText + " " + styles.endText + " col"}>
{components()}
</div>
</div>
);
};
export default MainComponent;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是代码有错误,但这对您有帮助!
this is code i think have error but this is help you !