A common misconception about React is that you need to set up an entire toolchain to get started with it. While that might have been true in the past, that certainly isn’t the case today.
From the React Docs:
The majority of websites aren’t, and don’t need to be, single-page apps. With a few lines of code and no build tooling, try React in a small part of your website. You can then either gradually expand its presence, or keep it contained to a few dynamic widgets.
Basically you need to do three things:
- Load React by including a prebuilt version
- Create a target container
- Render your app inside the container
Like so:
<!-- 1. Load React -->
<script src="https://unpkg.com/react@16/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js" crossorigin></script>
<!-- 2. Create a target container -->
<div id="root"></div>
<!-- 3. Render your app inside the container -->
<script>
ReactDOM.render(
<p>Hello from React {React.version}!</p>,
document.getElementById('root')
);
</script>
💡 This approach also works fine for legacy projects where you want to sneak in some React 🙂
This way you can jump right in and get started with it. It’s only later – for example when you start shipping into production and have no control over the browsers being used – that you might need Babel and the lot. You can of course always use create-react-app
which takes away the hassle of setting up your React Dev Environment.
👨🏫 This topic is also covered in my workshop React from Scratch. If you’re new to React I’d heartedly recommend it 😉
Thank me with a coffee.
I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!
To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.