Share Your Code with Others
The word counter we’ve built in the previous chapter executes as soon as the page loads. It’d be easier to integrate it in another application if we could decide when and where the word counter appears, without knowing how React works. To let others without React knowledge use your components in their own application, let’s adapt the webpack configuration to make the word counter a library.
If another developer wants to use your word counter library, they will probably expect to access the word counter through the Wordcounter global variable. They’d then assume that calling init should create the word counter on the element with app id. However, because of how things currently work, this will fail.
Try this out yourself ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access