@react-pdf/renderer
https://gyazo.com/b32f5b540977646da11b1a332c10316f
docs
github
React v18で使うときの対応
https://gist.github.com/gitname/bdc1fb7fe5bd0c22f6656b7905f57cd6#solution-b-use-overrides-property
package.jsonのoverridesを使う
内部でYogaを使ってるのでYogaは全ての<View/>はdefaultでdisplay: flexを持つ
なのでdisplay: 'flex'の指定はしてもしなくても変わらない
ここにdisplayの項目があるがdefaultでflex
もう一つの値はnone
React Nativeの実装に近い
code:ts
import React from 'react';
import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';
// Create styles
const styles = StyleSheet.create({
page: {
flexDirection: 'row',
backgroundColor: '#E4E4E4'
},
section: {
margin: 10,
padding: 10,
flexGrow: 1
}
});
// Create Document Component
const MyDocument = () => (
<Document>
<Page size="A4" style={styles.page}>
<View style={styles.section}>
<Text>Section #1</Text>
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
);
react-pdfが提供するComponentを使用し、styleもflexboxベース
Yogaを使っているので、RNと近いのは当然という感じがする
全く同じ名前の別ライブラリがある
wojtekmaj/react-pdf
こちらはPDFファイルをReact上でプレビューするもの