React: Create React App
Create new app
npm install -g create-react-app
Generate app
jsx
is name of app.
create-react-app jsx
Run app
npm start
App will run at localhost:3000
.
Possible errors
Port is in use - open new tab in terminal and run npm start
again. You can then view your app on localhost:3001
localhost:8080 doesnt’t work - go back to terminal and search for On your network
and visit that url.
index.js
// Import the React and ReactDOM libraries
import React from 'react';
import ReactDOM from 'react-dom';
// Create a react component
const App = () => {
return <div>Hi there!</div>;
}
// Take the react component and show it on the screen
ReactDOM.render(
<App />,
document.querySelector('#root')
);
Div root
is available in index.html
.