Skip to content
Ben Foley edited this page Jul 31, 2019 · 4 revisions

Let's play with changing the default app

File structure

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_modules is where React and the other Javascript libraries are
  • package.json has some information about this project
  • public is where our project gets built to when we are ready to distribute it
  • src is 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.lock

Edit the contente

So, 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.


JSX

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 (
  ...

Clone this wiki locally