Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Building a Trivia App With React

DZone's Guide to

Building a Trivia App With React

Check out this Jeopardy-like trivia app built using React, ES6, Babel, and Webpack.

Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

I sometimes use a Trivia app at the end of my talks as a replacement for the traditional summary slide, and we have also been using Trivia games as a fun activity at different Salesforce Developer events.

In this article, I share a React version of the Trivia application. The app was written with React and ES6 (ES2015), and was built with Babel and Webpack.

Check out a hosted version here: https://ccoenraets.github.io/react-trivia/

Make It Your Own

The questions in the example above are just placeholders. It’s easy to create your own questions:

  1. Click here to download the app
  2. Modify data.js with your own questions. The questions are loaded this way so you can easily load index.html from the local file system (using the file:// protocol) without running into XHR cross-origin issues. See the commented out componentDidMount in app.js for an alternative XHR implementation.
  3. Open index.html. You can just double-click index.html on your local file system: no need for a web server.

Source Code and Build Instructions

The source code is available in this repository if you want to modify the app and create your own build:

1 - Clone the repo

git clone https://github.com/ccoenraets/react-trivia

2 - Install dependencies

npm install

3 - Modify the app in the /js folder

4 - Build the app

npm run webpack 

Credits

Initially inspired by Ember Jeopardy.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
reactjs ,react js ,es6 ,babel ,webpack ,babeljs

Published at DZone with permission of Christophe Coenraets. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}