I would like to have a page that renders a Slate Editor, retrieves a document from an API, and then prints the window when the Editor has updated and finished re-rendering. How can I identify when the Editor has re-rendered?
Example code:
componentDidMount() {
$.get('/api/')
.done((data) => {
this.setState({ document: Value.fromJSON(data) });
// workaround to try and make sure document is rendered
// what can I do here instead??
setTimeout(() => window.print(), 500);
});
}
render() {
const { document } = this.state;
return (
<Editor
value={document}
readOnly
...
/>
);
I tried using componentDidUpdate
in the parent component:
componentDidUpdate(prevProps, prevState) {
window.print();
}
But the function gets triggered before the editor is fully rendered, so the text doesn't display in the Print dialog: