Getting started with ReactJS
We have discussed details of ReactJS that what is react and why to use it, we will continue further about how to use react. If you want to know about react and its benefits visit my previous blog.
In this blog we will be discussing the following:
- How to set up the environment.
- Writing our first React JS app.
- Some common errors that initially you could face.
Setting up a development environment
Install Node JS
- Visit https://nodejs.org/en/
- Install the latest version of NodeJS.
- Update the version of NodeJS if it is already installed.
Install Text Editor
I prefer VS Code as a code editor of development as it helps with syntax highlighting, bracket-matching, auto-indentation, box selection, snippets, and more. You can check more about VS Code from the link below
- Visit https://code.visualstudio.com/
- Install the latest version of VS Code.
- Update the version of the code editor if it is already installed.
Our First React App (Hello World)
1. Create React App
$ npx create-react-app app-name
$ cd my-app
$ npm start
Once your app is created successfully your browser will open as the figure above. Open the editor again, on the right side of the editor you will see the file structure as shown below in the figure under Projects.
Under your app name, there will be a list of files that are created initially by default.
2. Editing the Code
In your app drop-down expend src and open the App.js file.
Copy this simple code to display “Hello World” in App.js, save the file to check your output.
import './App.css';function App() { return ( <div className="App"> <h1>Hello World</h1> </div> );}export default App;
Here comes our output screen:
Common Errors
- When keeping the name of your app make sure that you don't use the camel case convention. Using capital letters in the app will generate an error.
Solution:
$ npm uninstall -g create-react-app
$ npm uninstall create-react-app
$ npx create-react-app app-name
References
https://reactjs.org/docs/getting-started.html
https://www.youtube.com/watch?v=QFaFIcGhPoM&list=PLC3y8-rFHvwgg3vaYJgHGnModB54rxOk3&index=1
https://stackoverflow.com/questions/59188624/template-not-provided-using-create-react-app