Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons


LoginGet Started

Register to 4Geeks

← Back to Projects

Simple Counter

Difficulty

  • easy

Average duration

4 hrs

Technologies

  • reactjs

Difficulty

  • easy

Average duration

4 hrs

Technologies

  • reactjs

A simple counter is the perfect project web you are in your early steps of learning the React.js library.

We are going to create a visual countdown to showcase the concept of React Components and how you can leverage component properties (props) to reuse those components easily.

A custom component allows you to "divide and conquer", separating logical and visual challenges into smaller pieces- giving you greater control over the display and functionalities of each part of the web-app.

For example, to create a bootstrap <Card /> component you'd code this:

1function Card(props){ 2 return ( 3 <div className="card"> 4 <img className="card-img-top" src="http://via.placeholder.com/350x150" alt="Card image cap" /> 5 <div className="card-body"> 6 <h5 className="card-title">Card title</h5> 7 <p className="card-text">Some quick example text to build on the card title and fill the card's content.</p> 8 <a href="#" className="btn btn-primary">Go somewhere</a> 9 </div> 10 </div> 11 ); 12}

After declaring it, you can import and use it in your webapp like this:

1// Import react into the bundle 2import React from 'react'; 3import ReactDOM from 'react-dom'; 4import Card from './component/Card.jsx' 5 6const root = ReactDOM.createRoot(document.querySelector('#root')); 7root.render(<App />); 8 9// If you are using a previous version from React v18 10// you have to use ReactDOM.render instead of createRoot 11// like this: 12// ReactDOM.render(<Card />, document.querySelector('#root'));

πŸ’‘ Note how ReactDOM.createRoot is a function you have to use only one time in your entire application

Additionally, you can pass information through the Card component using props:

1// Use of the custom component 2<Card imageUrl="http://via.placeholder.com/350x150" title="A nice image" />

For usage within the render method of your Card component (notice the image src and card title):

1// Declaration of a custom component (Card.jsx) 2 3function Card(props){ 4 return ( 5 <div className="card"> 6 <img className="card-img-top" src={props.imageUrl} alt="Card image cap" /> 7 <div className="card-body"> 8 <h5 className="card-title">{props.title}</h5> 9 <p className="card-text">Some quick example text to build on the card title and fill the card's content.</p> 10 <a href="#" className="btn btn-primary">Go somewhere</a> 11 </div> 12 </div> 13 ); 14}

🌱 How to start this project

Do not clone this repository because we are going to be using a different template.

We recommend opening the react boilerplate using a provisioning tool like Codespaces (recommended) or Gitpod. Alternatively, you can clone it on your local computer using the git clone command.

This is the repository you need to open or clone:

1https://github.com/4GeeksAcademy/react-hello

πŸ‘‰ Please follow these steps on how to start a coding project.

πŸ’‘ Important: Remember to save and upload your code to GitHub by creating a new repository, updating the remote (git remote set-url origin <your new url>), and uploading the code to your new repository using the add, commit and push commands from the git terminal.

πŸ“ Instructions

Create a seconds-counter component, called SecondsCounter. It should look like this one.

  • The whole purpose of the component is to display how many seconds have passed since the website finished loading (onLoad).
  • Use the ReactDOM.createRoot to render the component into the web-app.
  • Use the setInterval() function to re-render the component every second.
  • The component does not need a local state, you can pass the number of seconds as props, like this:
1<SecondsCounter seconds={3434} />
  • You can find the clock icon on the left of the component in Font Awesome.

πŸ”₯ Bonus

  • Create an option to countdown from a given number.
  • Create stop, reset, and resume functionality.
  • Create an alert when the user reaches a specified time. If the user enters "10", an alert should render, notifying the user that their time was reached.

This and many other projects are built by students as part of the 4Geeks Academy Coding Bootcamp by Alejandro Sanchez and many other contributors. Find out more about our Full Stack Developer Course, and Data Science Bootcamp.

Sign up and get access to solution files and videos

We will use it to give you access to your account.
Already have an account? Login here.

Difficulty

  • easy

Average duration

4 hrs

Technologies

  • reactjs

Difficulty

  • easy

Average duration

4 hrs

Technologies

  • reactjs

Difficulty

  • easy

Average duration

4 hrs

Technologies

  • reactjs

Difficulty

  • easy

Average duration

4 hrs

Technologies

  • reactjs

Sign up and get access to solution files and videos

We will use it to give you access to your account.
Already have an account? Login here.

Difficulty

  • easy

Average duration

4 hrs

Technologies

  • reactjs

Difficulty

  • easy

Average duration

4 hrs

Technologies

  • reactjs