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 ...

Get React for Real now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.