Can't seem to replace PDF
domehead100 opened this issue · 3 comments
If I render a and then later with a different url prop, it seems that the previously rendered PDF is not replaced with the new one. I tried a force update (after obtaining a ref on the PDFObject component), but to no avail.
Having this issue too unfortunately.
Found a solution, so you'll need to get the index.tsx under src and add that into your project directory.
Mine was a react-app so I did yarn add typescript @types/node @types/react @types/react-dom @types/jest @types/pdfobject
(last one needed as it's a dependency)
https://facebook.github.io/create-react-app/docs/adding-typescript
After that I added the contents of componentDidMount() to a new function and call that function in render() so it's like
public componentDidMount() {
const { url, containerId, containerProps, ...options } = this.props;
// for the SSR
if (pdfobject) {
pdfobject.embed(url, `#${containerId}`, options);
}
}
public renderPDF() {
const { url, containerId, containerProps, ...options } = this.props;
// for the SSR
if (pdfobject) {
pdfobject.embed(url, `#${containerId}`, options);
}
}
public render() {
this.renderPDF()
return <div { ...this.props.containerProps } id = { this.props.containerId } />;
}
This probably isn't the proper way to do it, but it works and serves as a baseline, and you can share your improvements.
Thanks!