У меня проблема с React-Pdf
У меня есть страница с переводимым содержимым, переведенные значения добавляются новым вызовом API.
Эти данныехранится в состоянии (приставка)
При обновлении страницы Новый документ PDF имеет добавленные страницы вместо сброса предыдущей.
componentDidMount(prevProp) {
const downloadContent = (
<Document>
<Page size='A4' style={ styles.page } wrap>
<View style={ styles.header } fixed><Image src={ logoWhite } style={ styles.headerLogo } /></View>
// initial content
</View>
</Page>
</Document>
);
this.setState({
...this.state,
downloadContent: downloadContent,
});
}
componentDidUpdate(prevProp) {
const downloadContent = (
<Document>
{ company && (
<Page size='A4' style={ styles.page } wrap>
<View style={ styles.header } fixed><Image src={ logoWhite } style={ styles.headerLogo } /></View>
// updated content
</View>
</Page>
)}
</Document>
);
this.setState({
...this.state,
downloadContent: downloadContent,
});
}
Здесь создается PDF.
render(){
const {
styles,
downloadContent,
} = this.state;
const {
company
} = this.props;
return (
downloadContent && (
<PDFDownloadLink
style={ styles.downloadLink }
document={ downloadContent }
fileName={ company ? `${ company.name }.pdf` : 'company.pdf' }
className='company-menu-button uppercase'
>
<span className='icon-DocMedium download-icon' />
{ company && (
<span style={ styles.downloadText }>
{ this.translate('download_pdf') }
</span>
)}
</PDFDownloadLink>
)
);
}