
Tip: Minify JavaScript for Productionīefore deploying your website to production, be mindful that unminified JavaScript can significantly slow down the page for your users. Inside React code, it’s easier to use component composition instead. This strategy is mostly useful while React-powered parts of the page are isolated from each other. Here is an example that displays the “Like” button three times and passes some data to it: You have just added the first React component to your website.Ĭheck out the next sections for more tips on integrating React.ĭownload the full example (2KB zipped) Tip: Reuse a ComponentĬommonly, you might want to display React components in multiple places on the HTML page. These three lines of code find the we added to our HTML in the first step, create a React app with it, and then display our “Like” button React component inside of it. querySelector ( '#like_button_container' ) const root = ReactDOM. Add an empty tag to mark the spot where you want to display something with React. Optional: Download the full example (2KB zipped) Step 1: Add a DOM Container to the HTMLįirst, open the HTML page you want to edit.
#REACT JS EXAMPLE UNPKG INSTALL#
There will be no complicated tools or install requirements - to complete this section, you only need an internet connection, and a minute of your time. You can follow along with your own website, or create an empty HTML file to practice.
#REACT JS EXAMPLE UNPKG HOW TO#
In this section, we will show how to add a React component to an existing HTML page.

The majority of websites aren’t, and don’t need to be, single-page apps.

React components are a great way to do that. Perhaps you only want to add some “sprinkles of interactivity” to an existing page. React has been designed from the start for gradual adoption, and you can use as little or as much React as you need. Use as little or as much React as you need.
