Let’s experiment with React and JSX using the Code Sandbox online IDE :
Code Sandbox is like VS Code in your browser.
It includes support for npm modules and will automatically bundle and transpile our code.
Take a moment to explore the Code Sandbox React template files:
public/index.html - Contains a div#root element where we’ll be rendering our React app.src/App.js - Exports a single React component named App.src/index.js - Renders the App component into the div#root element of the index.html file.src/styles.css - We won’t be making use of these styles.package.json - Defines the required React npm dependencies.Let’s add our Hello component to the project.
Create a new file called Hello.js in the src folder:
import React from "react";
export default function Hello() {
const greeting = "Hello Component";
return <p>{greeting}</p>;
}
Update App.js to look like this:
import React from "react";
import Hello from "./Hello";
export default function App() {
return (
<div>
<h1>Hello CodeSandbox</h1>
<Hello />
</div>
);
}
You should now see the contents of the App component in the Code Sandbox preview window.
Please take a moment to read through the comments included with this pre-made version of the same project: