diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.52k stars 1.14k forks source link

Can't integrate with React-intl #2354

Open withpublic opened 1 year ago

withpublic commented 1 year ago

I am trying to localize react-pdf using react-intl, but I get Unhandled Runtime Error Error: [React Intl] Could not find required intl object. needs to exist in the component ancestry.

I created a Viewer component and wrapped with injectIntl from react-intl package. It is a standard way of internationalization of the components. As soon as I wrapped it with injectIntl I got above error.

The component is as follows, simplified

import {Document, Page, View} from "@react-pdf/renderer";
import React, {Component} from "react";
import {injectIntl} from "react-intl";

class Viewer extends Component {
    render() {
        let {intl}=this.props;

        return (
            <Document>
                <Page style={styles.body} wrap>
                    <View
                        style={{
                            height: 100, textAlign: "center", width: "50%",
                            marginHorizontal: "auto"
                        }}>
                        {/*//Some components*/}
                    </View>
                </Page>
            </Document>
        );
    }
}

export default injectIntl(Viewer);
withpublic commented 1 year ago

Cross-posted here https://www.brainpick.co.uk/questions/cant-integrate-with-react-intl-261, with a reward.

ShaunaMack commented 4 months ago

Hi @diegomura @withpublic . I am just wondering if you have any idea what is causing this bug or if there are any work-arounds we could use until it's fixable?

PS. thanks @diegomura for your work on react-pdf – it's a very useful tool.