React Starter Tutorial

Created for CSE 370

Getting Started

Part 1
Part 2
Part 3
Part 4
Part 5
Part 6
React Routing
Styling the navbar
Part 9
Part 10
Part 11
Part 12
Part 13
Part 14
Conclusion

Additional Resources

W3Schools React Tutorial
Official ReactJS Tutorial
ReactJS Documentation

Routing and Navigation

Creating the navbar

In previous sections of this tutorial, we discussed what a functional component was. We’re going to create a navbar component as a functional component in this section of the tutorial.

Let’s start by creating a new file called ‘navbar.js’. Inside this file, add the following skeleton code for our navbar component. Most of what you see should be familiar, so make sure to review earlier parts of the tutorial if anything here looks foreign to you.

import React from 'react';


const NavBar = () => {
    return (
            <nav>
            <ul>
                <li>List item 1</li>
                <li>List item 2</li>
                <li>List item 3</li>
            </ul>
            </nav>
    );
}
export default NavBar;

Let’s go ahead and see what this looks like. Head over to your App.js file to get the ball rolling. Make sure to import the component first. Next, replace the child elements of the parent div tag with the newly-created Navbar component. Your app.js code should look like this:

// We need to import React so we can create a React component
import React from 'react';
import NavBar from './navbar';

// Here is how we will create a new Class component. Named App.
class App extends React.Component {
 

    render() {
        return (
            <div>
                <NavBar/>
            </div>
        );
    }
}

export default App;

For now, you will just see a simple list. That’s fine. We’re going to use CSS in the next section to make that look a lot prettier.

Part 8 ->