Repository navigation
2 jsx
If you don't have a code editor, install one (see the tools wiki page).
Then open the project in the editor. You should see some folders and files:
-
node_modulesis where React and the other Javascript libraries are -
package.jsonhas some information about this project -
publicis where our project gets built to when we are ready to distribute it -
srcis the app code that we will edit.
.
├── README.md
├── node_modules
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ └── manifest.json
├── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ └── serviceWorker.js
└── yarn.lockSo, as the app suggests (have a look at the browser again), open the App.js file in your editor.
Just to demonstrate where the content is rendered, delete all the code between the header tags and write your name there instead. You should end up with this:
import React from 'react';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
ben
</header>
</div>
);
}
export default App;Save the file and go back to the browser to see the change.
The App.js file is a component, a fundamental building block of React. It is an odd mix of Javascript and HTML-looking code. This mashup of code is known as JSX.
Read this article for a description of JSX
After reading that article, let's change the JSX in our App.js file to practise displaying data.
Inside the App() function, define a new variable (check the Javascript wiki page for more information about variables) and give it a value. (This code snippet is just showing these few lines from the whole file.)
function App() {
const name = "ben"
return (
...