我正在做这个完全动态的渲染,我有一个问题,在标题和副标题道具中,我想传递一个地图中的值,我不想传递它硬编码,但我不想'不知道我怎么能通过它。
alist
更新:
我设法像这样改变它,现在我可以将道具发送到每个组件,我只怀疑放置它是哪种类型,放置任何
interface Props {
questions:any[]
}
interface OptionsSurveys {
[key: string]: JSX.Element;
}
const FindSurveyComponents: React.FC<Props> = props => {
const { questions } = props
const components: OptionsSurveys = {
'star-rating': <StarRating
title={'Lorem Ipsum is simply dummy text of the printing and typesetting industry.?'}
subtitle={'Lorem Ipsum has been the industry's standard dummy text ever since the 1500s'}
/>,
'slider-grade': <SliderGrade
title={'Lorem Ipsum is simply dummy text of the printing and typesetting industry.?'}
subtitle={'Lorem Ipsum has been the industry's standard dummy text ever since the 1500s'}
/>,
'default': <Textarea
title={'Lorem Ipsum is simply dummy text of the printing and typesetting industry.?'}
/>
}
const mappingComponents = () => {
return (
questions.map((question:any) => {
const SurveyComponent = components[question.style]
return SurveyComponent
})
)
}
return (
<Fragment>
{questions && mappingComponents()}
</Fragment>
)
}