提问人:nnminh 提问时间:11/3/2023 更新时间:11/3/2023 访问量:21
如何在 React-pdf 中动态渲染多个<文本>
How to dynamically render multiple <Text> in React-pdf
问:
我有一个会动态变化的道具。我希望我的数量并据此动态增加或减少。有人可以帮我吗?谢谢!mainArray
<Document>
<View>
<Text>
const MyDocument = (mainArray:any) => {
return (
<Document>
<Page size="A4" style={styles.body}>
<View style={styles.section}>
<Text style={styles.title}>Don Quijote de la Mancha</Text>
</View>
{/* this is NOT working */}
<View render={() => (
mainArray&& (
<View style={styles.section}>
{
mainArray.map(() => (
// eslint-disable-next-line react/jsx-key
<Text style={styles.text}>
asdasdasdadsdads
</Text>
)
)
}
</View>
)
)} />
{/* this is working */}
<View style={styles.section}>
{
[1,2,3,4].map(() => (
// eslint-disable-next-line react/jsx-key
<Text style={styles.text}>
asdasdasdadsdads
</Text>
)
)
}
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
);
}```
I tried to use render in `<View>` as well as `<Text>` but <PDFViewer> just keep giving me a blank which I believe an internal Error
答: 暂无答案
评论