For our projects on the Qlik Demo Team, we’re now using React Hooks with functional components in place of class components. I’ve been playing around with ways to connect to a doc with enigma.js and use it in React components and this is what I’ve come up with most recently. Check out the code and notes below, or download the files and try it out yourself, and let me know what you think, if you like it or if you’re doing anything similar or if you have any ideas on improving it.
This file imports enigma.js and defines the config for connecting to a Qlik doc, and exports an openDoc function which returns a promise which will resolve to the doc.
This file creates and exports a React context and creates and exports a QDocProvider component. The QDocProvider component is responsible for connecting to the doc by calling the openDoc function from src/qDoc.config.js and storing the doc in state. Once the doc is available it renders the context provider and children.