• Skip to main content
  • Skip to search
  • Skip to select language
  • Sign up for free
  • English (US)

Getting started with React

  • Overview: Client-side JavaScript frameworks

In this article we will say hello to React. We'll discover a little bit of detail about its background and use cases, set up a basic React toolchain on our local computer, and create and play with a simple starter app — learning a bit about how React works in the process.

Hello React

As its official tagline states, React is a library for building user interfaces. React is not a framework – it's not even exclusive to the web. It's used with other libraries to render to certain environments. For instance, React Native can be used to build mobile applications.

To build for the web, developers use React in tandem with ReactDOM . React and ReactDOM are often discussed in the same spaces as — and utilized to solve the same problems as — other true web development frameworks. When we refer to React as a "framework", we're working with that colloquial understanding.

React's primary goal is to minimize the bugs that occur when developers are building UIs. It does this through the use of components — self-contained, logical pieces of code that describe a portion of the user interface. These components can be composed together to create a full UI, and React abstracts away much of the rendering work, leaving you to concentrate on the UI design.

Unlike the other frameworks covered in this module, React does not enforce strict rules around code conventions or file organization. This allows teams to set conventions that work best for them, and to adopt React in any way they would like to. React can handle a single button, a few pieces of an interface, or an app's entire user interface.

While React can be used for small pieces of an interface , it's not as easy to "drop into" an application as a library like jQuery, or even a framework like Vue — it is more approachable when you build your entire app with React.

In addition, many of the developer-experience benefits of a React app, such as writing interfaces with JSX, require a compilation process. Adding a compiler like Babel to a website makes the code on it run slowly, so developers often set up such tooling with a build step. React arguably has a heavy tooling requirement, but it can be learned.

This article is going to focus on the use case of using React to render the entire user interface of an application with the support of Vite , a modern front-end build tool.

How does React use JavaScript?

React utilizes features of modern JavaScript for many of its patterns. Its biggest departure from JavaScript comes with the use of JSX syntax. JSX extends JavaScript's syntax so that HTML-like code can live alongside it. For example:

This heading constant is known as a JSX expression . React can use it to render that <h1> tag in our app.

Suppose we wanted to wrap our heading in a <header> tag, for semantic reasons? The JSX approach allows us to nest our elements within each other, just like we do with HTML:

Note: The parentheses in the previous snippet aren't unique to JSX, and don't have any effect on your application. They're a signal to you (and your computer) that the multiple lines of code inside are part of the same expression. You could just as well write the header expression like this:

However, this looks kind of awkward, because the <header> tag that starts the expression is not indented to the same position as its corresponding closing tag.

Of course, your browser can't read JSX without help. When compiled (using a tool like Babel or Parcel ), our header expression would look like this:

It's possible to skip the compilation step and use React.createElement() to write your UI yourself. In doing this, however, you lose the declarative benefit of JSX, and your code becomes harder to read. Compilation is an extra step in the development process, but many developers in the React community think that the readability of JSX is worthwhile. Plus, modern front-end development almost always involves a build process anyway — you have to downlevel modern syntax to be compatible with older browsers, and you may want to minify your code to optimize loading performance. Popular tooling like Babel already comes with JSX support out-of-the-box, so you don't have to configure compilation yourself unless you want to.

Because JSX is a blend of HTML and JavaScript, some developers find it intuitive. Others say that its blended nature makes it confusing. Once you're comfortable with it, however, it will allow you to build user interfaces more quickly and intuitively, and allow others to better understand your codebase at a glance.

To read more about JSX, check out the React team's Writing Markup with JSX article.

Setting up your first React app

There are many ways to create a new React application. We're going to use Vite to create a new application via the command line.

It's possible to add React to an existing project by copying some <script> elements into an HTML file, but using Vite will allow you to spend more time building your app and less time fussing with setup.

Requirements

In order to use Vite, you need to have Node.js installed. As of Vite 5.0, at least Node version 18 or later is required, and it's a good idea to run the latest long term support (LTS) version when you can. As of 24th October 2023, Node 20 is the latest LTS version. Node includes npm (the Node package manager).

To check your version of Node, run the following in your terminal:

If Node is installed, you'll see a version number. If it isn't, you'll see an error message. To install Node, follow the instructions on the Node.js website .

You may use the Yarn package manager as an alternative to npm but we'll assume you're using npm in this set of tutorials. See Package management basics for more information on npm and yarn.

If you're using Windows, you will need to install some software to give you parity with Unix/macOS terminal in order to use the terminal commands mentioned in this tutorial. Gitbash (which comes as part of the git for Windows toolset ) or Windows Subsystem for Linux ( WSL ) are both suitable. See Command line crash course for more information on these, and on terminal commands in general.

Also bear in mind that React and ReactDOM produce apps that only work on a fairly modern set of browsers like Firefox, Microsoft Edge, Safari, or Chrome when working through these tutorials.

See the following for more information:

  • "About npm" on the npm blog
  • "Introducing npx" on the npm blog
  • Vite's documentation

Initializing your app

The npm package manager comes with a create command that allows you to create new projects from templates. We can use it to create a new app from Vite's standard React template. Make sure you cd to the place you'd like your app to live on your machine, then run the following in your terminal:

This creates a moz-todo-react directory using Vite's react template.

Note: The -- is necessary to pass arguments to npm commands such as create , and the --template react argument tells Vite to use its React template.

Your terminal will have printed some messages if this command was successful. You should see text prompting you to cd to your new directory, install the app's dependencies, and run the app locally. Let's start with two of those commands. Run the following in your terminal:

Once the process is complete, we need to start a local development server to run our app. Here, we're going to add some command line flags to Vite's default suggestion to open the app in our browser as soon as the server starts, and use port 3000.

Run the following in your terminal:

Once the server starts, you should see a new browser tab containing your React app:

Screenshot of Firefox MacOS open to localhost:3000, showing an application made from Vite's React template

Application structure

Vite gives us everything we need to develop a React application. Its initial file structure looks like this:

index.html is the most important top-level file. Vite injects your code into this file so that your browser can run it. You won't need to edit this file during our tutorial, but you should change the text inside the <title> element in this file to reflect the title of your application. Accurate page titles are important for accessibility.

The public directory contains static files that will be served directly to your browser without being processed by Vite's build tooling. Right now, it only contains a Vite logo.

The src directory is where we'll spend most of our time, as it's where the source code for our application lives. You'll notice that some JavaScript files in this directory end in the extension .jsx . This extension is necessary for any file that contains JSX – it tells Vite to turn the JSX syntax into JavaScript that your browser can understand. The src/assets directory contains the React logo you saw in the browser.

The package.json and package-lock.json files contain metadata about our project. These files are not unique to React applications: Vite populated package.json for us, and npm created package-lock.json for when we installed the app's dependencies. You don't need to understand these files at all to complete this tutorial. However, if you'd like to learn more about them, you can read about package.json and package-lock.json in the npm docs. We also talk about package.json in our Package management basics tutorial.

Customizing our dev script

Before we move on, you might want to change your package.json file a little bit so that you don't have to pass the --open and --port flags every time you run npm run dev . Open package.json in your text editor and find the scripts object. Change the "dev" key so that it looks like this:

With this in place, your app will open in your browser at http://localhost:3000 every time you run npm run dev .

Note: You don't need the extra -- here because we're passing arguments directly to vite , rather than to a pre-defined npm script.

Exploring our first React component — <App />

In React, a component is a reusable module that renders a part of our overall application. Components can be big or small, but they are usually clearly defined: they serve a single, obvious purpose.

Let's open src/App.jsx , since our browser is prompting us to edit it. This file contains our first component, <App /> :

The App.jsx file consists of three main parts: some import statements at the top, the App() function in the middle, and an export statement at the bottom. Most React components follow this pattern.

Import statements

The import statements at the top of the file allow App.jsx to use code that has been defined elsewhere. Let's look at these statements more closely.

The first statement imports the useState hook from the react library. Hooks are a way of using React's features inside a component. We'll talk more about hooks later in this tutorial.

After that, we import reactLogo and viteLogo . Note that their import paths start with ./ and / respectively and that they end with the .svg extension at the end. This tells us that these imports are local , referencing our own files rather than npm packages.

The final statement imports the CSS related to our <App /> component. Note that there is no variable name and no from directive. This is called a side-effect import — it doesn't import any value into the JavaScript file, but it tells Vite to add the referenced CSS file to the final code output, so that it can be used in the browser.

The App() function

After the imports, we have a function named App() , which defines the structure of the App component. Whereas most of the JavaScript community prefers lower camel case names like helloWorld , React components use Pascal case (or upper camel case) variable names, like HelloWorld , to make it clear that a given JSX element is a React component and not a regular HTML tag. If you were to rename the App() function to app() , your browser would throw an error.

Let's look at App() more closely.

The App() function returns a JSX expression. This expression defines what your browser ultimately renders to the DOM.

Just under the return keyword is a special bit of syntax: <> . This is a fragment . React components have to return a single JSX element, and fragments allow us to do that without rendering arbitrary <div> s in the browser. You'll see fragments in many React applications.

The export statement

There's one more line of code after the App() function:

This export statement makes our App() function available to other modules. We'll talk more about this later.

Moving on to main

Let's open src/main.jsx , because that's where the <App /> component is being used. This file is the entry point for our app, and it initially looks like this:

As with App.jsx , the file starts by importing all the JS modules and other assets it needs to run.

The first two statements import the React and ReactDOM libraries because they are referenced later in the file. We don't write a path or extension when importing these libraries because they are not local files. In fact, they are listed as dependencies in our package.json file. Be careful of this distinction as you work through this lesson!

We then import our App() function and index.css , which holds global styles that are applied to our whole app.

We then call the ReactDOM.createRoot() function, which defines the root node of our application. This takes as an argument the DOM element inside which we want our React app to be rendered. In this case, that's the DOM element with an ID of root . Finally, we chain the render() method onto the createRoot() call, passing it the JSX expression that we want to render inside our root. By writing <App /> as this JSX expression, we're telling React to call the App() function which renders the App component inside the root node.

Note: <App /> is rendered inside a special <React.StrictMode> component. This component helps developers catch potential problems in their code.

You can read up on these React APIs, if you'd like:

  • ReactDOM.createRoot()
  • React.StrictMode

Starting fresh

Before we start building our app, we're going to delete some of the boilerplate code that Vite provided for us.

First, as an experiment, change the <h1> element in App.jsx so that it reads "Hello, World!", then save your file. You'll notice that this change is immediately rendered in the development server running at http://localhost:3000 in your browser. Bear this in mind as you work on your app.

We won't be using the rest of the code! Replace the contents of App.jsx with the following:

Practice with JSX

Next, we'll use our JavaScript skills to get a bit more comfortable writing JSX and working with data in React. We'll talk about how to add attributes to JSX elements, how to write comments, how to render content from variables and other expressions, and how to pass data into components with props.

Adding attributes to JSX elements

JSX elements can have attributes, just like HTML elements. Try adding a <button> below the <h1> element in your App.jsx file, like this:

When you save your file, you'll see a button with the words Click me! . The button doesn't do anything yet, but we'll learn about adding interactivity to our app soon.

Some attributes are different than their HTML counterparts. For example, the class attribute in HTML translates to className in JSX. This is because class is a reserved word in JavaScript, and JSX is a JavaScript extension. If you wanted to add a primary class to your button, you'd write it like this:

JavaScript expressions as content

Unlike HTML, JSX allows us to write variables and other JavaScript expressions right alongside our other content. Let's declare a variable called subject just above the App() function:

Next, replace the word "World" in the <h1> element with {subject} :

Save your file and check your browser. You should see "Hello, React!" rendered.

The curly braces around subject are another feature of JSX's syntax. The curly braces tell React that we want to read the value of the subject variable, rather than render the literal string "subject" . You can put any valid JavaScript expression inside curly braces in JSX; React will evaluate it and render the result of the expression as the final content. Following is a series of examples, with comments above explaining what each expression will render:

Even comments in JSX are written inside curly braces! This is because comments, too, are technically JavaScript expressions. The /* block comment syntax */ is necessary for your program to know where the comment starts and ends.

Component props

Props are a means of passing data into a React component. Their syntax is identical to that of attributes, in fact: prop="value" . The difference is that whereas attributes are passed into plain elements, props are passed into React components.

In React, the flow of data is unidirectional: props can only be passed from parent components down to child components.

Let's open main.jsx and give our <App /> component its first prop.

Add a prop of subject to the <App /> component call, with a value of Clarice . When you are done, it should look something like this:

Back in App.jsx , let's revisit the App() function. Change the signature of App() so that it accepts props as a parameter and log props to the console so you can inspect it. Also delete the subject const; we don't need it anymore. Your App.jsx file should look like this:

Save your file and check your browser. You'll see a blank background with no content. This is because we're trying to read a subject variable that's no longer defined. Fix this by commenting out the <h1>Hello {subject}!</h1> line.

Note: If your code editor understands how to parse JSX (most modern editors do!), you can use its built-in commenting shortcut — Ctrl + / (on Windows) or Cmd + / (on macOS) — to create comments more quickly.

Save the file with that line commented out. This time, you should see your "Click me!" button rendered by itself. If you open your browser's developer console, you'll see a message that looks like this:

The object property subject corresponds to the subject prop we added to our <App /> component call, and the string Clarice corresponds to its value. Component props in React are always collected into objects in this fashion.

Let's use this subject prop to fix the error in our app. Uncomment the <h1>Hello, {subject}!</h1> line and change it to <h1>Hello, {props.subject}!</h1> , then delete the console.log() statement. Your code should look like this:

When you save, the app should now greet you with "Hello, Clarice!". If you return to main.jsx , edit the value of subject , and save, your text will change.

For additional practice, you could try adding an additional greeting prop to the <App /> component call inside main.jsx and using it alongside the subject prop inside App.jsx .

This brings us to the end of our initial look at React, including how to install it locally, creating a starter app, and how the basics work. In the next article, we'll start building our first proper application — a todo list. Before we do that, however, let's recap some of the things we've learned.

  • Components can import modules they need and must export themselves at the bottom of their files.
  • Component functions are named with PascalCase .
  • You can render JavaScript expressions in JSX by putting them between curly braces, like {so} .
  • Some JSX attributes are different than HTML attributes so that they don't conflict with JavaScript reserved words. For example, class in HTML translates to className in JSX.
  • Props are written just like attributes inside component calls and are passed into components.

Getting Started

These docs are old and won’t be updated. Go to react.dev for the new React docs. The new Quick Start teaches modern React and includes live examples.

This page is an overview of the React documentation and related resources.

React is a JavaScript library for building user interfaces. Learn what React is all about on our homepage or in the tutorial .

Learn React

Staying informed, versioned documentation, something missing.

React has been designed from the start for gradual adoption, and you can use as little or as much React as you need. Whether you want to get a taste of React, add some interactivity to a simple HTML page, or start a complex React-powered app, the links in this section will help you get started.

Online Playgrounds

If you’re interested in playing around with React, you can use an online code playground. Try a Hello World template on CodePen , CodeSandbox , or Stackblitz .

If you prefer to use your own text editor, you can also download this HTML file , edit it, and open it from the local filesystem in your browser. It does a slow runtime code transformation, so we’d only recommend using this for simple demos.

Add React to a Website

You can add React to an HTML page in one minute . You can then either gradually expand its presence, or keep it contained to a few dynamic widgets.

Create a New React App

When starting a React project, a simple HTML page with script tags might still be the best option. It only takes a minute to set up!

As your application grows, you might want to consider a more integrated setup. There are several JavaScript toolchains we recommend for larger applications. Each of them can work with little to no configuration and lets you take full advantage of the rich React ecosystem. Learn how.

People come to React from different backgrounds and with different learning styles. Whether you prefer a more theoretical or a practical approach, we hope you’ll find this section helpful.

  • If you prefer to learn by doing , start with our practical tutorial .
  • If you prefer to learn concepts step by step , start with our guide to main concepts .

Like any unfamiliar technology, React does have a learning curve. With practice and some patience, you will get the hang of it.

First Examples

The React homepage contains a few small React examples with a live editor. Even if you don’t know anything about React yet, try changing their code and see how it affects the result.

React for Beginners

If you feel that the React documentation goes at a faster pace than you’re comfortable with, check out this overview of React by Tania Rascia . It introduces the most important React concepts in a detailed, beginner-friendly way. Once you’re done, give the documentation another try!

React for Designers

If you’re coming from a design background, these resources are a great place to get started.

JavaScript Resources

The React documentation assumes some familiarity with programming in the JavaScript language. You don’t have to be an expert, but it’s harder to learn both React and JavaScript at the same time.

We recommend going through this JavaScript overview to check your knowledge level. It will take you between 30 minutes and an hour but you will feel more confident learning React.

Tip Whenever you get confused by something in JavaScript, MDN and javascript.info are great websites to check. There are also community support forums where you can ask for help.

Practical Tutorial

If you prefer to learn by doing, check out our practical tutorial . In this tutorial, we build a tic-tac-toe game in React. You might be tempted to skip it because you’re not into building games — but give it a chance. The techniques you’ll learn in the tutorial are fundamental to building any React apps, and mastering it will give you a much deeper understanding.

Step-by-Step Guide

If you prefer to learn concepts step by step, our guide to main concepts is the best place to start. Every next chapter in it builds on the knowledge introduced in the previous chapters so you won’t miss anything as you go along.

Thinking in React

Many React users credit reading Thinking in React as the moment React finally “clicked” for them. It’s probably the oldest React walkthrough but it’s still just as relevant.

Recommended Courses

Sometimes people find third-party books and video courses more helpful than the official documentation. We maintain a list of commonly recommended resources , some of which are free.

Advanced Concepts

Once you’re comfortable with the main concepts and played with React a little bit, you might be interested in more advanced topics. This section will introduce you to the powerful, but less commonly used React features like context and refs .

API Reference

This documentation section is useful when you want to learn more details about a particular React API. For example, React.Component API reference can provide you with details on how setState() works, and what different lifecycle methods are useful for.

Glossary and FAQ

The glossary contains an overview of the most common terms you’ll see in the React documentation. There is also a FAQ section dedicated to short questions and answers about common topics, including making AJAX requests , component state , and file structure .

The React blog is the official source for the updates from the React team. Anything important, including release notes or deprecation notices, will be posted there first.

You can also follow the @reactjs account on Twitter, but you won’t miss anything essential if you only read the blog.

Not every React release deserves its own blog post, but you can find a detailed changelog for every release in the CHANGELOG.md file in the React repository , as well as on the Releases page.

This documentation always reflects the latest stable version of React. Since React 16, you can find older versions of the documentation on a separate page . Note that documentation for past versions is snapshotted at the time of the release, and isn’t being continuously updated.

If something is missing in the documentation or if you found some part confusing, please file an issue for the documentation repository with your suggestions for improvement, or tweet at the @reactjs account . We love hearing from you!

  • Next article Add React to a Website

DEV Community

DEV Community

Stephen Gbolagade

Posted on Mar 24, 2023 • Updated on Mar 29, 2023

Complete Reactjs Tutorial for Beginners: Step-by-step Guide (Part 1)

If you're interested in learning Reactjs but don't know where to start, this step-by-step guide is for you. In this blog post, I'll break down Reactjs and provide a comprehensive tutorial that will help you build your first React application.

But before we dive, let's quickly remind ourselves what React is.

Section 1: What is Reactjs?

To simply understand this, I would like to use Wikipedia's definition . It says:

> React (which is also called Reactjs) is a free and open-source front-end JavaScript library for building user interfaces based on components.

Let me break it down further.

Reactjs is created by the team at Meta , previously Facebook, and released for the public free of charge. It is used to build the user-facing part of a web application.

That is, it can be used to build any frontend application.

It's important to note that Reactjs is built on JavaScript. As a beginner, it's necessary to have basic knowledge of JavaScript, although you don't need to be an expert.

It's also worth mentioning that Reactjs is a library, not a framework. If you want to know the differences between a framework and a library, read this blog post by @tacomanick .

Now that we know what we're learning, let's talk about the requirements to start learning it.

Section 2: Requirements to Learn Reactjs

If you're planning to become a web developer, it's essential to learn HTML , CSS , and JavaScript . These three languages are the foundation of web development, and without them, it's impossible to build a web application.

HTML is the skeleton of your web application, while CSS is used to style websites. JavaScript is a multi-purpose programming language that powers the web. According to Wikipedia , 98% of websites worldwide use JavaScript.

It's crucial to have basic knowledge of JavaScript before diving into Reactjs. You don't need to master JavaScript, but you should know the basic concepts, including data types, math operators, array methods, JavaScript functions, conditions, and template literals.

Aside from the web, like I said earlier that JavaScript is a multi-purpose programming language, you can use it to build mobile apps, games, AI tools , etc.

It's so compulsory that you learn these 3 languages before you dive into reactjs.

But to which extent should you know JavaScript before learning Reactjs?

Section 3: Basics of JavaScript You Must Learn Before Reactjs

Here are important stuffs you need to learn:

I. Data types

You should be able to differentiate between a string, float, integer, enum etc. As you grow in your career, you'll learn Typescript which is a cool subset of JavaScript.

II. Maths Operators

This is just the basic mathematics you learned in primary school… How do you use "+", "-", "÷", "%", and other maths operators?

III. Array methods

This is so important because throughout your life as a software engineer, especially a frontend developer, you'll be working on arrays of data.

You're going to use map method a lot, so do take your time to learn Array methods.

IV. JavaScript functions

You should know how to use the arrow function and the primitive function syntax.

These two code blocks are the same, but you have to learn the differences before choosing one syntax.

V. Conditions

Just like we make decisions in our daily life, we need to also make decisions when building websites or something with a programming language and this is where conditional statements shine.

We have different ways of making decisions in JavaScript and they are:

If-else statement

Ternary operation, switch statement.

These 3 code blocks are different ways to make decisions in JavaScript, you have to know how to use each of them and when to use them.

VI. Template literal: This saves you stress of long and unnecessary concatenation.

For instance, compare the code blocks below:

As long as this will work perfectly, do you notice that + " " + is repeated? If we don't do it that way, we will not get the expected result.

But the syntax is ugly and time-consuming, that's why we have template literals to fix that. Consider this block of code below:

Do you notice that this second code block is cleaner and faster? That's the benefit of template literal.

The syntax is simple, wrap your string with this symbol ( press the key before 1 on your keyboard ).

And if you need to use a stored or dynamic string, like the languages we stored in our function above, you'll use a dollar sign followed by curly brackets. Like this:

As simple as that.

If you’ve learned these stuff in JavaScript, then you’re good to go.

Now coming to Reactjs ecosystem might seem different compared to writing code with HTML and CSS because React has a syntax called JSX.

What that simply means is that you can write HTML, CSS, and JavaScript in the same file without any errors.

An example is this:

Note that I use the 3 languages, HTML, CSS, and JavaScript here. This is a simple ReactJs component and you’re going to work with a lot of it.

Conclusion: Reactjs Tutorial for Beginners (PART 1)

In conclusion, Reactjs is an essential library for frontend development. To start learning Reactjs, it's important to have basic knowledge of HTML, CSS, and JavaScript. In this tutorial, we covered the basics of JavaScript that you need to know before diving into Reactjs.

Stay tuned for Part 2 of this tutorial, where we'll dive deeper into Reactjs and build our first React application. To get notified when it drops, kindly follow me, and feel free to share this with others.

UPDATE : Here is the part 2

> You can connect with me on Twitter or Linkedin - I'm also open to Frontend engineering and technical writing role.

Top comments (0)

pic

Templates let you quickly answer FAQs or store snippets for re-use.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink .

Hide child comments as well

For further actions, you may consider blocking this person and/or reporting abuse

sidddharthamishra profile image

Parcel with React

Siddhartha Mishra - Feb 18

uliyahoo profile image

How to build: an AI PowerPoint generator (Next.js, OpenAI, CopilotKit)

uliyahoo - Feb 20

fredabod profile image

A Simple Crud App With Prisma, Express, and PostgreSQL

FredAbod - Feb 21

superprotocolperson profile image

Challenges in Advancing Web3: Understanding the Role of Decentralized Confidential Cloud Computing

Super Protocol Dev - Feb 16

Once suspended, stephengade will not be able to comment or publish posts until their suspension is removed.

Once unsuspended, stephengade will be able to comment and publish posts again.

Once unpublished, all posts by stephengade will become hidden and only accessible to themselves.

If stephengade is not suspended, they can still re-publish their posts from their dashboard.

Once unpublished, this post will become invisible to the public and only accessible to Stephen Gbolagade.

They can still re-publish the post if they are not suspended.

Thanks for keeping DEV Community safe. Here is what you can do to flag stephengade:

stephengade consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy.

Unflagging stephengade will restore default visibility to their posts.

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

React Tutorial

  • React Exercise

React Basic Concepts

React components.

  • React Props

React Hooks

  • React Advanced
  • React Examples

React Interview Questions

  • React Projects
  • Next.js Tutorial
  • React React Bootstrap
  • React Material UI
  • React Ant Design
  • React React Desktop
  • React React Rebass
  • React Blueprint
  • Web Technology

Related Articles

  • Solve Coding Problems
  • React Introduction
  • React Environment Setup

React Fundamentals

  • ReactJS Babel Introduction
  • ReactJS Virtual DOM
  • React JS ReactDOM
  • ReactJS Lists
  • ReactJS forms
  • ReactJS Keys
  • ReactJS Refs
  • ReactJS Rendering Elements
  • ReactJS Conditional Rendering
  • Code Splitting in React
  • ReactJS Components
  • ReactJS | Components - Set 2
  • ReactJS Pure Components
  • ReactJS Functional Components
  • ReactJS Lifecycle of Components
  • Differences between Functional Components and Class Components
  • ReactJS Container and Presentational Pattern in Components

React Props & States

  • ReactJS Methods as Props
  • ReactJS PropTypes
  • ReactJS Props - Set 1
  • ReactJS Props - Set 2
  • ReactJS Unidirectional Data Flow
  • ReactJS State
  • ReactJS State vs Props
  • ReactJS Hooks
  • ReactJS useState Hook
  • ReactJS useEffect Hook
  • Context in React
  • ReactJS Router
  • React JS Types of Routers
  • ReactJS Fragments
  • Create ToDo App using ReactJS
  • Create a Quiz App using ReactJS
  • Create a Coin Flipping App using ReactJS
  • How to create a Color-Box App using ReactJS?
  • Dice Rolling App using ReactJS
  • Guess the number with React

React Connection & Deployment

  • How to Deploy Your React Websites on GitHub?
  • How to Deploy React project on Firebase?
  • How to deploy React app to Heroku?
  • How to deploy React app to Surge ?
  • How to deploy simple frontend server-less (static) React applications on Netlify

React Exercises

  • React Exercises, Practice Questions and Solutions

React Questions

  • How to connect Django with Reactjs ?
  • 7 React Best Practices Every Web Developer Should Follow
  • 8 Ways to Style React Components
  • How to add Stateful component without constructor class in React?
  • How to display a PDF as an image in React app using URL?
  • React JS Toast Notification
  • What is the use of data-reactid attribute in HTML ?
  • How to zoom-in and zoom-out image using ReactJS?
  • How to avoid binding by using arrow functions in callbacks in ReactJS?
  • How to bind 'this' keyword to resolve classical error message 'state of undefined' in React?
  • How to get the height and width of an Image using ReactJS?
  • How to handle multiple input field in react form with a single function?
  • How to handle states of mutable data types?
  • How to change state continuously after a certain amount of time in React?
  • How to change the state of react component on click?

React Tutorial: This free React tutorial is designed for people who prefer to learn by doing. So if you are a beginner or advanced React developer, this tutorial will guide you through all the fundamentals to build any React app and master React development.

React is one of the most popular, efficient, and powerful open-source JavaScript libraries for building dynamic and interactive user interfaces. Whether you are a beginner or an experienced developer, React Tutorial will significantly enhance your development skills. ReactJS is not a framework, it is just a library developed by Facebook.

html react tutorial

What you Learn in this React Tutorial?

In this tutorial, you will get a hands-on several sections of React development

  • Setup for this react development tutorial from scratch.
  • Fundamental of React
  • Building a first React app
  • Important React packages
  • Advanced concepts in React

Also Check: Recent Articles on ReactJS

Why Learn React JS?

ReactJS is famous for its component-based architecture and virtual DOM which makes it highly efficient in rendering user interface and ensuring optimal performance. Due to its reusable components, It is very helpful in the efficient development and maintenance of large-scale applications. ReactJS has a vast ecosystem and community which makes the development very easy and ensures performance optimization.

ReactJS Advantages

  • Composable: We can divide these codes and put them in custom components. Then we can utilize those components and integrate them into one place.
  • Declarative: In ReactJS, the DOM is declarative. We can make interactive UIs by changing the state of the component and ReactJS takes care of updating the DOM according to it.
  • SEO Friendly: ReactJS affects the SEO by giving you a SPA (Single Page Application) which requires Javascript to show the content on the page which can be rendered and indexed.
  • Community: ReactJS has a huge community because of its demand each company wants to work with ReactJS. Companies like Meta, Netflix, etc built on ReactJS.
  • Easy to learn: HTML-like syntax of JSX makes you comfortable with the codes of React, it only requires a basic knowledge of HTML, CSS, and JS fundamentals to start working with it.
  • If you want to learn more refer to this article React JS Advantages
  • Debugging is Easy: The debugging of ReactJS is unidirectional which means while designing any app using ReactJS the child components are nested within parent components. So, the data flow is in a single direction it gets more easier to debug errors.

Geting Started with Free ReactJS Tutorial

Here are the ReactJS important topics that come under in this tutorial. After completing all the important topics in this free tutorial for React, you’ll have a basic understanding of the ReactJS:-

ReactJS Tutorial – Prerequisites

Well, before proceeding towards this ReactJS tutorial there is some prerequisites needed. So we assume that all the readers of this page have a basic knowledge of HTML , CSS , OPPS and JavaScript .

  • Introduction
  • Import and Export
  • JSX Introduction
  • Conditional Rendering
  • Prop Drilling
  • React Lists
  • Context API
  • React Redux
  • Hooks Introduction
  • useState Hook
  • useEffect Hook
  • useRef Hook
  • useMemo Hook
  • useContext Hook

React DOM Events

  • React Events Introduction
  • onclickcapture Event
  • onMouseDown Event
  • onDoubleClick Event
  • onSubmit Event
  • onScroll Event
  • onBlur Event

Lifecycle of Components

  • Introduction to lifecycle of components
  • constructor
  • componentDidMount
  • componentWillUnmount
  • componentDidCatch
  • componentDidUpdate
  • shouldComponentUpdate

Important React Packages

  • Material UI
  • react-bootstrap
  • Framer Motion
  • Beginner Level Interview Questions (2024)
  • Intermediate Level Interview Questions (2024)
  • Advanced Level Interview Questions (2024)
  • 7 Most Asked ReactJS Interview Questions

ReactJS Online Quizs

First react app.

A Project will always help you to be confident in your learning path, so we recommend you to follow the below-mentioned articles after you clear your fundamentals of React by following our React Basics section.

  • Introduction (Calculator App)
  • Building UI (Calculator App)
  • Adding Functionality (Calculator App)
  • Styling (Calculator App)

If you want to build more projects to enhance your knowledge about key concepts of ReactJS, refer to the Top ReactJS Projects to build in 2023 article.

React Online Practice Exercise

Embark on your React learning journey with our online practice portal. Start by selecting quizzes tailored to your skill level. Engage in hands-on coding exercises, receive real-time feedback, and monitor your progress. With our user-friendly platform, mastering React becomes an enjoyable and personalized experience. Elevate your coding expertise by going through our carefully curated Free Online React Quiz.

React Complete References

Refer to the following articles to have a quick glance at all the important key concepts which are helpful while developing web applications using React

  • Basic Concepts Reference
  • Components Complete Reference
  • Props Reference
  • Events Reference

If you want to have a simple, quick reference to commonly used React methods you can refer to ReactJS Cheat Sheet article

Popular Apps and Websites Using ReactJS

  • In this section, we have listed down popular apps and websites using ReactJS. So, if you think that ReactJS is not that popular then explore this list.
  • Facebook : On of the most used social media apps Facebook, uses ReactJS to design their application.
  • Instagram : World’s most popular photo-sharing site Instagram is also using ReactJS. Features of Instagram including Geo-location, Hashtags, and Google Maps APIs using ReactJS.
  • Netflix : Most used or one of the popular media streaming sites Netflix also uses ReactJS. Netflix switched their site to ReactJS in 2015.
  • Reddit : The content-sharing site Reddit is also developed using ReactJS.

ReactJS Jobs & Opporunities

If you were thinking is there any future or career in ReactJS then here in this section, we have listed down companies that hire ReactJS

  • Amazon India

Avarage Salary of ReactJS Developer in 2024

Reactsjs online compiler, reactsjs – frequently asked questions, 1. what is reactjs used for.

The primary goal of ReactJS is to create a User Interface, Single-Page Application, Progressive Web Application and more.

2. Which language is used in ReactJS?

ReactJS used Javascript programming language.

3. Is ReactJS a front-end language?

ReactJS globally used for Front-end JS framework and it popular with both software and project speoncer.

4. Which is in demand ReactJS or AngulerJS in 2024?

React is far more popular than AngulerJS because ReactJS comes with more libraries.

5. Which is better NodeJS or ReactJS or AngularJS

Choosing the framework always depends very much on your requirements. All of these three frameworks are quite popular, and users choose them based on what they want to do. But if we do so more specifically, then ReatJS is better.

6. Is this ReactJS tutorial for beginners or for advanced

As we said at the beginning of this article, this course is for beginners as well as for advanced. 

Please Login to comment...

  • Web Technologies
  • ashishbhardwaj18
  • thakurshubhamkumar

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Learn ReactJS – Complete Roadmap

Web Development is a fascinating area to explore, learn about, and understand.

As a learner, you have many libraries and frameworks that can help you develop projects for the web. It may even become tricky to pick one and get started at times.

But when it comes to learning ReactJS , it shouldn't be a difficult decision to make.

ReactJS (aka React) is an open-source JavaScript-based user interface library. It is insanely popular in web development communities today. React Native is equally popular among mobile application developers.

In this article, we will look at a complete roadmap to learn ReactJS. If you are thinking of starting ReactJS and looking to get a step-by-step approach, this article is for you. Also, if you are a ReactJS developer who is wondering what advanced topics to tackle next, give this article a read.

Why do you need a roadmap to learn React?

Good question. Think about it this way. You are in an unknown city, and you have to travel from one place to another. What you need most is a map or guide to help with your travels.

Learning something new doesn't have to be very different. If you have a map or guide that lets you know "if you first learn A, next attempt to learn B. Then you will find C much easier", things will be much smoother for you.

It may also help you decide on alternative routes, how far to go at a stretch, and when to pause.

In this guide, we will break things down into phases and build the roadmap to learn ReactJS. You will also find resources to look into (optionally) as we explore the roadmap further.

👀 Keep in mind that you may feel a bit overwhelmed looking at this roadmap the first time. But don't worry. It is not as challenging as it looks. I have also specified some resources to help you learn at an incredible pace.

I have created this roadmap based on my 6+ years of working experience with ReactJS. So in case you disagree with certain things, I am okay with that.

As ReactJS is very popular, you may find some resemblance here with many other suggested roadmaps out there. But, they aren't exactly the same.

Breaking the roadmap down into phases

We will break the entire roadmap into four phases. They will be:

  • What to learn before React
  • What to learn as a beginner to React
  • How to move from beginner to intermediate React developer
  • How to move from intermediate to advanced React developer

What to Learn Before You Learn React

ReactJS is JavaScript-based. You'll need to be familiar with a few things (other than basic JavaScript knowledge) to accelerate your React learning at full speed.

🔵 Git Version Control

Git is a version control tool that helps you manage your source code better. It doesn't have a direct relationship with ReactJS. But it helps if you learn its basic uses so you can take advantage of the development ecosystem.

Git is easy to learn when you focus on a few basic things like,

  • How to initiate a repository
  • How to stage/unstage your changes
  • How to commit your changes to the repo
  • How to push to the remote repository
  • How to resolve merge conflicts?

Along with Git , you will also need to know how to use a Git-based repository management service like GitHub . You can learn all about Git and GitHub in this YouTube playlist: Git and GitHub Playlist .

HTML provides the structure of a web page. You will use the HTML structure in a new syntax called JSX when you code in ReactJS.

You don't need to know everything about HTML. But you should have a basic knowledge of the most-used tags and semantics. You can check out this HTML crash course for beginners and this HTML basics guide to get started.

You can also check out freeCodeCamp's newly-updated Responsive Web Design certification to get started with HTML.

When it comes to CSS, the scope is sky-high. However, focus on the topics I have mentioned in this Tweet:

CSS? - Basic Selectors - Pseudo-classes and how to combine - Box Model - Flexbox - Grid - Positioning(relative, absolute) - Units(px, em, rem, vh....) What else? IMO, if we know the above, that's 80% of it. Rest 20% is google search. No one remembers properties 😀. — Tapas Adhikary (@tapasadhikary) January 24, 2022

You can learn a lot about CSS on the CSS-Tricks site, and here's a project-based tutorial to help you put basic CSS concepts into practice.

You can also check out freeCodeCamp's Responsive Web Design certification to learn CSS.

🔵 JavaScript

You must know the following concepts from JavaScript,

  • Variable Declarations (let and const)
  • Template Literals
  • Functions & Arrow Functions
  • Object Destructuring
  • Spread and Rest Operators
  • Module Import and Export
  • A bit of Promises and Async Programming

freeCodeCamp also has a JavaScript certification if you want to check that out.

🔵 NPM Ecosystem

You should be aware of how to use npm , yarn , and node version manager (nvm) to help you run and test a ReactJs app locally.

Knowing how they work at a high level is always helpful to debug your environment in case you run into issues. Here is a resource to help you get started with all these quickly: Node.js install, npm, yarn, nvm .

🔵 How to Deploy, Host, and Make your App Public:

It won't be much fun if you have created something cool with ReactJS and cannot showcase it to the world. So, you should know how to deploy the app and make it available for public access.

Tools like Vercel or Netlify make it easy to deploy your React app with a few clicks. Here's a tutorial, for example, on deploying your React app to Netlify .

What to Learn as a Beginner to React

Let's now focus on what you need to learn at the minimum to start enjoying React in practice. These are foundational pieces, so make sure to give enough time and hands-on effort to truly understand the concepts.

There is a famous saying called "Think in React". These fundamental concepts should help you to develop that "Think in React" mindset.

🟡 Understand What React Is

You should understand what is so special about ReactJs. It is a declarative, component-based user interface library.

What does all this mean? Check out this video that explains all these concepts clearly.

🟡 Learn How to Set Up your Development Environment

There are multiple ways to set up a development environment for ReactJs. Minimally, you can point to the CDN distribution from your script file.

This approach is okay to get started but not sustainable. As a beginner, you may not want to spend too much time in Babel or Webpack related configurations for your projects.

IMO, the most intelligent and quickest way to get started with the ReactJS development environment is by using the Create React App . You can follow the easy steps on its homepage to get it running in a few minutes.

🟡 Learn about JSX

ReactJS allows the user interface logic to couple with rendering logic, events, handling state changes, and more. This coupling is to encourage the practices of building self-contained components.

JSX is a syntax that looks like HTML but also has the power of JavaScript . This syntax helps developers write UI logic with all necessary elements like data fetching, conditions, looping, expressions, etc.

Note that you can write a ReactJS app without using JSX syntax – but the development experience will not be as good.

Here's a great resource to help you learn about JSX in React .

🟡 Learn about React Components

Components are the heart of ReactJs applications. We create independent components that are reusable, self-contained, and isolated. A component is supposed to perform one job correctly. Multiple components come together to build the application.

In ReactJS, you can create components using JavaScript classes or simple functions. I advocate using functional components as it is more straightforward and require lesser coding.

Here's an article about how to write better React components , and here's one about using React components instead of HTML .

🟡 State in React

State is the data private to your component. We do not share states across components. The "state" of your component that you use to render information and modify information.

You can check out this in-depth guide to state in React to get a better understanding of how it works.

🟡 Props in React

In real-world programming, you will need the components to interact with each other. States are private to a component, but you need to pass the data between components. That's where Props come into the picture. Note that props are read-only.

Here's a quick introductory tutorial about how to use props in React . And here's a helpful cheatsheet that shares 10 props patterns you should know .

Finally, here's a beginner-friendly article about props and state in React in case you need to clear any basics up.

🟡 Lists and Keys in React

We use list to render a list of items in a React component. It is a very common task to list users, TODO items, and other things. We use the map() function to iterate over the list and render the results.

keys help identify what item from the list has changed to inform React to re-render. ReactJS gives a warning if you forget to mention the keys for a list.

🟡 Life Cycle Methods in React

We discussed that the "state" is a component's private matter. State can be dynamic and might need modifications. We also need to perform resource cleanups when components are destroyed. ReactJs provides various life-cycle methods to detect the phases and take action.

If you are just getting started with ReactJS, you should understand life cycle management for functional components. You can do this using the in-built hooks like useState , useEffect , and so on.

Here's a helpful video you can check out to understand the React component lifecycle . And here's an article that'll teach you React Hooks basics .

And if you need an overall beginner's guide to solidify these concepts, here's an in-depth React Handbook to get you started.

How to Move from Beginner to Intermediate React Developer

Let's now understand what it takes to move from a beginner to intermediate level with React.

In this phase, you will start focusing on the completeness of the application. At the end of this phase, you will be able to take up most ReactJs challenges and enjoy accomplishing them.

🟣 Styling in React

We all want our applications to look fresh and aesthetically pleasing. You can use plain old CSS to style your ReactJS app. Or you can use Sass or other CSS-driven component libraries like TailwindCSS , ChakraUI , react-bootstrap , or MUI . The choice is entirely yours.

As an example, here's a tutorial about styling your React apps with TailwindCSS .

🟣 Form Handling in React

Handling forms is an essential requirement in web applications. You need to understand how to handle form elements in the ReactJS way.

For example, you can use the react-hook-form library to build forms easily. Here are a couple tutorials to get you started with react-hook-form .

🟣 Data Handling in React

This is a crucial part of application development. You need to learn how to use the fetch API or libraries like node-fetch and axios to interact with APIs and handle data in your component.

Here's a cheatsheet to get you started with the Fetch API , and here's an in-depth guide on how to use Axios with React .

🟣 Reconciliation Process in React

ReactJS uses the Virtual DOM and diffing algorithm to decide when and what to update in the actual DOM for the rendering. Knowing how it works under the hood will help you with debugging.

Here's a good starter guide on the DOM , or Document Object Model, and here's one on how to manipulate the DOM . Then you can check out this overview of the Virtual DOM and how it works in React.

🟣 React Hooks

You hopefully learned a bit about some in-built hooks like useState useEffect when you learn about the life-cycle. There are other useful built-in hooks you need to learn with use-cases. Make sure you don't ignore them.

Here's a fun project-based guide on how to learn React Hooks by building a Paint app .

🟣 Custom React Hooks

Custom hooks helps in reusability. You must look for opportunities to extract out component logic to reusable hooks. The code becomes clean and modular with the usage of custom hooks.

Here's a step-by-step guide on how to build your own custom React Hooks .

🟣 Context in React

In React applications, we pass data from parent to child components. It is one-directional and top-down. If too many components are deep down, the data (props) must pass through many components.

Also, if you need to share some values between components that are not part of a hierarchy, you need a mechanism. That's when you can make use of the Context .

You can learn all about React context in this beginner-friendly guide .

How to Move from Intermediate to Advanced React Developer

In this phase, you will deal with a few expert-level topics. You need to know these concepts only when you're working on more extensive application development using ReactJS.

Note that you can learn each of these concepts whenever you're ready. Also, you don't have to learn them all.

🟢 Lazy Loading in React

ReactJS supports code splitting. It is a way to lazy load what you need by the current user. It also avoids producing a large build bundle. The dynamic import feature is the best way to include code-splitting in a React app.

Here's a basic tutorial on lazy loading in React to get you started.

🟢 Portals in React

You may have to use Portals when dealing with modals, dialogs, or tooltips with better event handling. It is supported out-of-the-box in ReactJS.

🟢 State Management in React

In a larger application, you must share information between components. At times, the default support of Props and Context may not suffice.

In these cases, you may need a state management solution like Redux or MobX in these cases. But again, you can decide whether (or not) you'll need them.

Here's a handy Redux for beginners guide that you can use to get started. Then, if you want to dive deep and learn all about Redux, here's a full book you can read .

🟢 Routing in React

Routing is required for multi-page applications. It is also helpful to bookmark a particular page or traverse back-and-forth in the application using the browser's back button.

React Router is the most popular routing solution that helps with declarative routing.

Here's an in-depth guide to learning React Router that'll get you started with all the basics.

🟢 Theming in React

Theming is a modern feature in web apps. We should give users the choice of what theme they want – like light or dark – to use to help them feel comfortable when using your site or app.

You can even create your custom themes in some applications and apply them. There are several ways you can theme a React app. Select the one that matches the best with your application's CSS stack.

🟢 Patterns in React

There are various patterns you can use as solutions to common problems in React. Over time, ReactJS developers have found patterns they could use to help them stop reinventing the wheel.

Learning these patterns will help you considerably. Check out this site to find the most used ReactJS Patterns documented with examples.

🟢 Anti-Patterns in React

Anti-Patterns are the practices that you should avoid using in the ReactJS applications. You should learn them along with the helpful patterns you should use.

Just keep in mind that learning advanced React concepts doesn't stop here. You can continue to learn about accessibility, test frameworks, and many more advanced concepts as needed.

So, How Do You Get Started with React?

That's the billion-dollar question! There are plenty of great resources (books, articles, videos) to help you with the above topics, many of which are linked in each section. So, you can find the ones that suit you the best.

You can also check out these resources:

  • ReactJS Official Documentation
  • freeCodeCamp's front-end development library course
  • After spending many years with ReactJS, I have started creating a YouTube video series that aims to cover all the aspects we discussed in the article. Please SUBSCRIBE if you find it helpful.

Should I Still Learn React?

Another frequently asked question – and the answer is YES. React is ever-growing, and the community is also growing quickly. There is no reason to stay back.

Also, React is a base for many other popular frameworks like Next.js , GatsbyJS , and very recently Remix .

I am not comparing React with the Angular, Vue, or Svelte frameworks. They are all excellent in their ways, like how ReactJS is an excellent library for user interface development.

Before We End...

I hope you found the roadmap helpful. Please plan to get enough practice as you start walking through the path. My DMs are open on Twitter if you want to discuss further.

Let's connect. I share my learnings on JavaScript, Web Development, and Blogging on these platforms as well:

  • Follow me on Twitter
  • Subscribe to my YouTube Channel
  • Side projects on GitHub

See you soon with my next article. Until then, please take care of yourself, and stay happy.

Writer . YouTuber . Creator . Mentor

If you read this far, thank the author to show them you care. Say Thanks

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Tutorial: Tic-Tac-Toe

You will build a small tic-tac-toe game during this tutorial. This tutorial does not assume any existing React knowledge. The techniques you’ll learn in the tutorial are fundamental to building any React app, and fully understanding it will give you a deep understanding of React.

This tutorial is designed for people who prefer to learn by doing and want to quickly try making something tangible. If you prefer learning each concept step by step, start with Describing the UI.

The tutorial is divided into several sections:

  • Setup for the tutorial will give you a starting point to follow the tutorial.
  • Overview will teach you the fundamentals of React: components, props, and state.
  • Completing the game will teach you the most common techniques in React development.
  • Adding time travel will give you a deeper insight into the unique strengths of React.

What are you building?

In this tutorial, you’ll build an interactive tic-tac-toe game with React.

You can see what it will look like when you’re finished here:

If the code doesn’t make sense to you yet, or if you are unfamiliar with the code’s syntax, don’t worry! The goal of this tutorial is to help you understand React and its syntax.

We recommend that you check out the tic-tac-toe game above before continuing with the tutorial. One of the features that you’ll notice is that there is a numbered list to the right of the game’s board. This list gives you a history of all of the moves that have occurred in the game, and it is updated as the game progresses.

Once you’ve played around with the finished tic-tac-toe game, keep scrolling. You’ll start with a simpler template in this tutorial. Our next step is to set you up so that you can start building the game.

Setup for the tutorial

In the live code editor below, click Fork in the top-right corner to open the editor in a new tab using the website CodeSandbox. CodeSandbox lets you write code in your browser and preview how your users will see the app you’ve created. The new tab should display an empty square and the starter code for this tutorial.

You can also follow this tutorial using your local development environment. To do this, you need to:

  • Install Node.js
  • In the CodeSandbox tab you opened earlier, press the top-left corner button to open the menu, and then choose Download Sandbox in that menu to download an archive of the files locally
  • Unzip the archive, then open a terminal and cd to the directory you unzipped
  • Install the dependencies with npm install
  • Run npm start to start a local server and follow the prompts to view the code running in a browser

If you get stuck, don’t let this stop you! Follow along online instead and try a local setup again later.

Now that you’re set up, let’s get an overview of React!

Inspecting the starter code

In CodeSandbox you’ll see three main sections:

CodeSandbox with starter code

  • The Files section with a list of files like App.js , index.js , styles.css and a folder called public
  • The code editor where you’ll see the source code of your selected file
  • The browser section where you’ll see how the code you’ve written will be displayed

The App.js file should be selected in the Files section. The contents of that file in the code editor should be:

The browser section should be displaying a square with a X in it like this:

x-filled square

Now let’s have a look at the files in the starter code.

The code in App.js creates a component . In React, a component is a piece of reusable code that represents a part of a user interface. Components are used to render, manage, and update the UI elements in your application. Let’s look at the component line by line to see what’s going on:

The first line defines a function called Square . The export JavaScript keyword makes this function accessible outside of this file. The default keyword tells other files using your code that it’s the main function in your file.

The second line returns a button. The return JavaScript keyword means whatever comes after is returned as a value to the caller of the function. <button> is a JSX element . A JSX element is a combination of JavaScript code and HTML tags that describes what you’d like to display. className="square" is a button property or prop that tells CSS how to style the button. X is the text displayed inside of the button and </button> closes the JSX element to indicate that any following content shouldn’t be placed inside the button.

Click on the file labeled styles.css in the Files section of CodeSandbox. This file defines the styles for your React app. The first two CSS selectors ( * and body ) define the style of large parts of your app while the .square selector defines the style of any component where the className property is set to square . In your code, that would match the button from your Square component in the App.js file.

Click on the file labeled index.js in the Files section of CodeSandbox. You won’t be editing this file during the tutorial but it is the bridge between the component you created in the App.js file and the web browser.

Lines 1-5 bring all the necessary pieces together:

  • React’s library to talk to web browsers (React DOM)
  • the styles for your components
  • the component you created in App.js .

The remainder of the file brings all the pieces together and injects the final product into index.html in the public folder.

Building the board

Let’s get back to App.js . This is where you’ll spend the rest of the tutorial.

Currently the board is only a single square, but you need nine! If you just try and copy paste your square to make two squares like this:

You’ll get this error:

React components need to return a single JSX element and not multiple adjacent JSX elements like two buttons. To fix this you can use Fragments ( <> and </> ) to wrap multiple adjacent JSX elements like this:

Now you should see:

two x-filled squares

Great! Now you just need to copy-paste a few times to add nine squares and…

nine x-filled squares in a line

Oh no! The squares are all in a single line, not in a grid like you need for our board. To fix this you’ll need to group your squares into rows with div s and add some CSS classes. While you’re at it, you’ll give each square a number to make sure you know where each square is displayed.

In the App.js file, update the Square component to look like this:

The CSS defined in styles.css styles the divs with the className of board-row . Now that you’ve grouped your components into rows with the styled div s you have your tic-tac-toe board:

tic-tac-toe board filled with numbers 1 through 9

But you now have a problem. Your component named Square , really isn’t a square anymore. Let’s fix that by changing the name to Board :

At this point your code should look something like this:

Psssst… That’s a lot to type! It’s okay to copy and paste code from this page. However, if you’re up for a little challenge, we recommend only copying code that you’ve manually typed at least once yourself.

Passing data through props

Next, you’ll want to change the value of a square from empty to “X” when the user clicks on the square. With how you’ve built the board so far you would need to copy-paste the code that updates the square nine times (once for each square you have)! Instead of copy-pasting, React’s component architecture allows you to create a reusable component to avoid messy, duplicated code.

First, you are going to copy the line defining your first square ( <button className="square">1</button> ) from your Board component into a new Square component:

Then you’ll update the Board component to render that Square component using JSX syntax:

Note how unlike the browser div s, your own components Board and Square must start with a capital letter.

Let’s take a look:

one-filled board

Oh no! You lost the numbered squares you had before. Now each square says “1”. To fix this, you will use props to pass the value each square should have from the parent component ( Board ) to its child ( Square ).

Update the Square component to read the value prop that you’ll pass from the Board :

function Square({ value }) indicates the Square component can be passed a prop called value .

Now you want to display that value instead of 1 inside every square. Try doing it like this:

Oops, this is not what you wanted:

value-filled board

You wanted to render the JavaScript variable called value from your component, not the word “value”. To “escape into JavaScript” from JSX, you need curly braces. Add curly braces around value in JSX like so:

For now, you should see an empty board:

empty board

This is because the Board component hasn’t passed the value prop to each Square component it renders yet. To fix it you’ll add the value prop to each Square component rendered by the Board component:

Now you should see a grid of numbers again:

Your updated code should look like this:

Making an interactive component

Let’s fill the Square component with an X when you click it. Declare a function called handleClick inside of the Square . Then, add onClick to the props of the button JSX element returned from the Square :

If you click on a square now, you should see a log saying "clicked!" in the Console tab at the bottom of the Browser section in CodeSandbox. Clicking the square more than once will log "clicked!" again. Repeated console logs with the same message will not create more lines in the console. Instead, you will see an incrementing counter next to your first "clicked!" log.

If you are following this tutorial using your local development environment, you need to open your browser’s Console. For example, if you use the Chrome browser, you can view the Console with the keyboard shortcut Shift + Ctrl + J (on Windows/Linux) or Option + ⌘ + J (on macOS).

As a next step, you want the Square component to “remember” that it got clicked, and fill it with an “X” mark. To “remember” things, components use state .

React provides a special function called useState that you can call from your component to let it “remember” things. Let’s store the current value of the Square in state, and change it when the Square is clicked.

Import useState at the top of the file. Remove the value prop from the Square component. Instead, add a new line at the start of the Square that calls useState . Have it return a state variable called value :

value stores the value and setValue is a function that can be used to change the value. The null passed to useState is used as the initial value for this state variable, so value here starts off equal to null .

Since the Square component no longer accepts props anymore, you’ll remove the value prop from all nine of the Square components created by the Board component:

Now you’ll change Square to display an “X” when clicked. Replace the console.log("clicked!"); event handler with setValue('X'); . Now your Square component looks like this:

By calling this set function from an onClick handler, you’re telling React to re-render that Square whenever its <button> is clicked. After the update, the Square ’s value will be 'X' , so you’ll see the “X” on the game board. Click on any Square, and “X” should show up:

Each Square has its own state: the value stored in each Square is completely independent of the others. When you call a set function in a component, React automatically updates the child components inside too.

After you’ve made the above changes, your code will look like this:

React Developer Tools

React DevTools let you check the props and the state of your React components. You can find the React DevTools tab at the bottom of the browser section in CodeSandbox:

React DevTools in CodeSandbox

To inspect a particular component on the screen, use the button in the top left corner of React DevTools:

For local development, React DevTools is available as a Chrome , Firefox , and Edge browser extension. Install it, and the Components tab will appear in your browser Developer Tools for sites using React.

Completing the game

By this point, you have all the basic building blocks for your tic-tac-toe game. To have a complete game, you now need to alternate placing “X”s and “O”s on the board, and you need a way to determine a winner.

Lifting state up

Currently, each Square component maintains a part of the game’s state. To check for a winner in a tic-tac-toe game, the Board would need to somehow know the state of each of the 9 Square components.

How would you approach that? At first, you might guess that the Board needs to “ask” each Square for that Square ’s state. Although this approach is technically possible in React, we discourage it because the code becomes difficult to understand, susceptible to bugs, and hard to refactor. Instead, the best approach is to store the game’s state in the parent Board component instead of in each Square . The Board component can tell each Square what to display by passing a prop, like you did when you passed a number to each Square.

To collect data from multiple children, or to have two child components communicate with each other, declare the shared state in their parent component instead. The parent component can pass that state back down to the children via props. This keeps the child components in sync with each other and with their parent.

Lifting state into a parent component is common when React components are refactored.

Let’s take this opportunity to try it out. Edit the Board component so that it declares a state variable named squares that defaults to an array of 9 nulls corresponding to the 9 squares:

Array(9).fill(null) creates an array with nine elements and sets each of them to null . The useState() call around it declares a squares state variable that’s initially set to that array. Each entry in the array corresponds to the value of a square. When you fill the board in later, the squares array will look like this:

Now your Board component needs to pass the value prop down to each Square that it renders:

Next, you’ll edit the Square component to receive the value prop from the Board component. This will require removing the Square component’s own stateful tracking of value and the button’s onClick prop:

At this point you should see an empty tic-tac-toe board:

And your code should look like this:

Each Square will now receive a value prop that will either be 'X' , 'O' , or null for empty squares.

Next, you need to change what happens when a Square is clicked. The Board component now maintains which squares are filled. You’ll need to create a way for the Square to update the Board ’s state. Since state is private to a component that defines it, you cannot update the Board ’s state directly from Square .

Instead, you’ll pass down a function from the Board component to the Square component, and you’ll have Square call that function when a square is clicked. You’ll start with the function that the Square component will call when it is clicked. You’ll call that function onSquareClick :

Next, you’ll add the onSquareClick function to the Square component’s props:

Now you’ll connect the onSquareClick prop to a function in the Board component that you’ll name handleClick . To connect onSquareClick to handleClick you’ll pass a function to the onSquareClick prop of the first Square component:

Lastly, you will define the handleClick function inside the Board component to update the squares array holding your board’s state:

The handleClick function creates a copy of the squares array ( nextSquares ) with the JavaScript slice() Array method. Then, handleClick updates the nextSquares array to add X to the first ( [0] index) square.

Calling the setSquares function lets React know the state of the component has changed. This will trigger a re-render of the components that use the squares state ( Board ) as well as its child components (the Square components that make up the board).

JavaScript supports closures which means an inner function (e.g. handleClick ) has access to variables and functions defined in a outer function (e.g. Board ). The handleClick function can read the squares state and call the setSquares method because they are both defined inside of the Board function.

Now you can add X’s to the board… but only to the upper left square. Your handleClick function is hardcoded to update the index for the upper left square ( 0 ). Let’s update handleClick to be able to update any square. Add an argument i to the handleClick function that takes the index of the square to update:

Next, you will need to pass that i to handleClick . You could try to set the onSquareClick prop of square to be handleClick(0) directly in the JSX like this, but it won’t work:

Here is why this doesn’t work. The handleClick(0) call will be a part of rendering the board component. Because handleClick(0) alters the state of the board component by calling setSquares , your entire board component will be re-rendered again. But this runs handleClick(0) again, leading to an infinite loop:

Why didn’t this problem happen earlier?

When you were passing onSquareClick={handleClick} , you were passing the handleClick function down as a prop. You were not calling it! But now you are calling that function right away—notice the parentheses in handleClick(0) —and that’s why it runs too early. You don’t want to call handleClick until the user clicks!

You could fix this by creating a function like handleFirstSquareClick that calls handleClick(0) , a function like handleSecondSquareClick that calls handleClick(1) , and so on. You would pass (rather than call) these functions down as props like onSquareClick={handleFirstSquareClick} . This would solve the infinite loop.

However, defining nine different functions and giving each of them a name is too verbose. Instead, let’s do this:

Notice the new () => syntax. Here, () => handleClick(0) is an arrow function, which is a shorter way to define functions. When the square is clicked, the code after the => “arrow” will run, calling handleClick(0) .

Now you need to update the other eight squares to call handleClick from the arrow functions you pass. Make sure that the argument for each call of the handleClick corresponds to the index of the correct square:

Now you can again add X’s to any square on the board by clicking on them:

But this time all the state management is handled by the Board component!

This is what your code should look like:

Now that your state handling is in the Board component, the parent Board component passes props to the child Square components so that they can be displayed correctly. When clicking on a Square , the child Square component now asks the parent Board component to update the state of the board. When the Board ’s state changes, both the Board component and every child Square re-renders automatically. Keeping the state of all squares in the Board component will allow it to determine the winner in the future.

Let’s recap what happens when a user clicks the top left square on your board to add an X to it:

  • Clicking on the upper left square runs the function that the button received as its onClick prop from the Square . The Square component received that function as its onSquareClick prop from the Board . The Board component defined that function directly in the JSX. It calls handleClick with an argument of 0 .
  • handleClick uses the argument ( 0 ) to update the first element of the squares array from null to X .
  • The squares state of the Board component was updated, so the Board and all of its children re-render. This causes the value prop of the Square component with index 0 to change from null to X .

In the end the user sees that the upper left square has changed from empty to having a X after clicking it.

The DOM <button> element’s onClick attribute has a special meaning to React because it is a built-in component. For custom components like Square, the naming is up to you. You could give any name to the Square ’s onSquareClick prop or Board ’s handleClick function, and the code would work the same. In React, it’s conventional to use onSomething names for props which represent events and handleSomething for the function definitions which handle those events.

Why immutability is important

Note how in handleClick , you call .slice() to create a copy of the squares array instead of modifying the existing array. To explain why, we need to discuss immutability and why immutability is important to learn.

There are generally two approaches to changing data. The first approach is to mutate the data by directly changing the data’s values. The second approach is to replace the data with a new copy which has the desired changes. Here is what it would look like if you mutated the squares array:

And here is what it would look like if you changed data without mutating the squares array:

The result is the same but by not mutating (changing the underlying data) directly, you gain several benefits.

Immutability makes complex features much easier to implement. Later in this tutorial, you will implement a “time travel” feature that lets you review the game’s history and “jump back” to past moves. This functionality isn’t specific to games—an ability to undo and redo certain actions is a common requirement for apps. Avoiding direct data mutation lets you keep previous versions of the data intact, and reuse them later.

There is also another benefit of immutability. By default, all child components re-render automatically when the state of a parent component changes. This includes even the child components that weren’t affected by the change. Although re-rendering is not by itself noticeable to the user (you shouldn’t actively try to avoid it!), you might want to skip re-rendering a part of the tree that clearly wasn’t affected by it for performance reasons. Immutability makes it very cheap for components to compare whether their data has changed or not. You can learn more about how React chooses when to re-render a component in the memo API reference .

Taking turns

It’s now time to fix a major defect in this tic-tac-toe game: the “O”s cannot be marked on the board.

You’ll set the first move to be “X” by default. Let’s keep track of this by adding another piece of state to the Board component:

Each time a player moves, xIsNext (a boolean) will be flipped to determine which player goes next and the game’s state will be saved. You’ll update the Board ’s handleClick function to flip the value of xIsNext :

Now, as you click on different squares, they will alternate between X and O , as they should!

But wait, there’s a problem. Try clicking on the same square multiple times:

The X is overwritten by an O ! While this would add a very interesting twist to the game, we’re going to stick to the original rules for now.

When you mark a square with a X or an O you aren’t first checking to see if the square already has a X or O value. You can fix this by returning early . You’ll check to see if the square already has a X or an O . If the square is already filled, you will return in the handleClick function early—before it tries to update the board state.

Now you can only add X ’s or O ’s to empty squares! Here is what your code should look like at this point:

Declaring a winner

Now that the players can take turns, you’ll want to show when the game is won and there are no more turns to make. To do this you’ll add a helper function called calculateWinner that takes an array of 9 squares, checks for a winner and returns 'X' , 'O' , or null as appropriate. Don’t worry too much about the calculateWinner function; it’s not specific to React:

It does not matter whether you define calculateWinner before or after the Board . Let’s put it at the end so that you don’t have to scroll past it every time you edit your components.

You will call calculateWinner(squares) in the Board component’s handleClick function to check if a player has won. You can perform this check at the same time you check if a user has clicked a square that already has a X or and O . We’d like to return early in both cases:

To let the players know when the game is over, you can display text such as “Winner: X” or “Winner: O”. To do that you’ll add a status section to the Board component. The status will display the winner if the game is over and if the game is ongoing you’ll display which player’s turn is next:

Congratulations! You now have a working tic-tac-toe game. And you’ve just learned the basics of React too. So you are the real winner here. Here is what the code should look like:

Adding time travel

As a final exercise, let’s make it possible to “go back in time” to the previous moves in the game.

Storing a history of moves

If you mutated the squares array, implementing time travel would be very difficult.

However, you used slice() to create a new copy of the squares array after every move, and treated it as immutable. This will allow you to store every past version of the squares array, and navigate between the turns that have already happened.

You’ll store the past squares arrays in another array called history , which you’ll store as a new state variable. The history array represents all board states, from the first to the last move, and has a shape like this:

Lifting state up, again

You will now write a new top-level component called Game to display a list of past moves. That’s where you will place the history state that contains the entire game history.

Placing the history state into the Game component will let you remove the squares state from its child Board component. Just like you “lifted state up” from the Square component into the Board component, you will now lift it up from the Board into the top-level Game component. This gives the Game component full control over the Board ’s data and lets it instruct the Board to render previous turns from the history .

First, add a Game component with export default . Have it render the Board component and some markup:

Note that you are removing the export default keywords before the function Board() { declaration and adding them before the function Game() { declaration. This tells your index.js file to use the Game component as the top-level component instead of your Board component. The additional div s returned by the Game component are making room for the game information you’ll add to the board later.

Add some state to the Game component to track which player is next and the history of moves:

Notice how [Array(9).fill(null)] is an array with a single item, which itself is an array of 9 null s.

To render the squares for the current move, you’ll want to read the last squares array from the history . You don’t need useState for this—you already have enough information to calculate it during rendering:

Next, create a handlePlay function inside the Game component that will be called by the Board component to update the game. Pass xIsNext , currentSquares and handlePlay as props to the Board component:

Let’s make the Board component fully controlled by the props it receives. Change the Board component to take three props: xIsNext , squares , and a new onPlay function that Board can call with the updated squares array when a player makes a move. Next, remove the first two lines of the Board function that call useState :

Now replace the setSquares and setXIsNext calls in handleClick in the Board component with a single call to your new onPlay function so the Game component can update the Board when the user clicks a square:

The Board component is fully controlled by the props passed to it by the Game component. You need to implement the handlePlay function in the Game component to get the game working again.

What should handlePlay do when called? Remember that Board used to call setSquares with an updated array; now it passes the updated squares array to onPlay .

The handlePlay function needs to update Game ’s state to trigger a re-render, but you don’t have a setSquares function that you can call any more—you’re now using the history state variable to store this information. You’ll want to update history by appending the updated squares array as a new history entry. You also want to toggle xIsNext , just as Board used to do:

Here, [...history, nextSquares] creates a new array that contains all the items in history , followed by nextSquares . (You can read the ...history spread syntax as “enumerate all the items in history ”.)

For example, if history is [[null,null,null], ["X",null,null]] and nextSquares is ["X",null,"O"] , then the new [...history, nextSquares] array will be [[null,null,null], ["X",null,null], ["X",null,"O"]] .

At this point, you’ve moved the state to live in the Game component, and the UI should be fully working, just as it was before the refactor. Here is what the code should look like at this point:

Showing the past moves

Since you are recording the tic-tac-toe game’s history, you can now display a list of past moves to the player.

React elements like <button> are regular JavaScript objects; you can pass them around in your application. To render multiple items in React, you can use an array of React elements.

You already have an array of history moves in state, so now you need to transform it to an array of React elements. In JavaScript, to transform one array into another, you can use the array map method:

You’ll use map to transform your history of moves into React elements representing buttons on the screen, and display a list of buttons to “jump” to past moves. Let’s map over the history in the Game component:

You can see what your code should look like below. Note that you should see an error in the developer tools console that says:

You’ll fix this error in the next section.

As you iterate through history array inside the function you passed to map , the squares argument goes through each element of history , and the move argument goes through each array index: 0 , 1 , 2 , …. (In most cases, you’d need the actual array elements, but to render a list of moves you will only need indexes.)

For each move in the tic-tac-toe game’s history, you create a list item <li> which contains a button <button> . The button has an onClick handler which calls a function called jumpTo (that you haven’t implemented yet).

For now, you should see a list of the moves that occurred in the game and an error in the developer tools console. Let’s discuss what the “key” error means.

Picking a key

When you render a list, React stores some information about each rendered list item. When you update a list, React needs to determine what has changed. You could have added, removed, re-arranged, or updated the list’s items.

Imagine transitioning from

In addition to the updated counts, a human reading this would probably say that you swapped Alexa and Ben’s ordering and inserted Claudia between Alexa and Ben. However, React is a computer program and does not know what you intended, so you need to specify a key property for each list item to differentiate each list item from its siblings. If your data was from a database, Alexa, Ben, and Claudia’s database IDs could be used as keys.

When a list is re-rendered, React takes each list item’s key and searches the previous list’s items for a matching key. If the current list has a key that didn’t exist before, React creates a component. If the current list is missing a key that existed in the previous list, React destroys the previous component. If two keys match, the corresponding component is moved.

Keys tell React about the identity of each component, which allows React to maintain state between re-renders. If a component’s key changes, the component will be destroyed and re-created with a new state.

key is a special and reserved property in React. When an element is created, React extracts the key property and stores the key directly on the returned element. Even though key may look like it is passed as props, React automatically uses key to decide which components to update. There’s no way for a component to ask what key its parent specified.

It’s strongly recommended that you assign proper keys whenever you build dynamic lists. If you don’t have an appropriate key, you may want to consider restructuring your data so that you do.

If no key is specified, React will report an error and use the array index as a key by default. Using the array index as a key is problematic when trying to re-order a list’s items or inserting/removing list items. Explicitly passing key={i} silences the error but has the same problems as array indices and is not recommended in most cases.

Keys do not need to be globally unique; they only need to be unique between components and their siblings.

Implementing time travel

In the tic-tac-toe game’s history, each past move has a unique ID associated with it: it’s the sequential number of the move. Moves will never be re-ordered, deleted, or inserted in the middle, so it’s safe to use the move index as a key.

In the Game function, you can add the key as <li key={move}> , and if you reload the rendered game, React’s “key” error should disappear:

Before you can implement jumpTo , you need the Game component to keep track of which step the user is currently viewing. To do this, define a new state variable called currentMove , defaulting to 0 :

Next, update the jumpTo function inside Game to update that currentMove . You’ll also set xIsNext to true if the number that you’re changing currentMove to is even.

You will now make two changes to the Game ’s handlePlay function which is called when you click on a square.

  • If you “go back in time” and then make a new move from that point, you only want to keep the history up to that point. Instead of adding nextSquares after all items ( ... spread syntax) in history , you’ll add it after all items in history.slice(0, currentMove + 1) so that you’re only keeping that portion of the old history.
  • Each time a move is made, you need to update currentMove to point to the latest history entry.

Finally, you will modify the Game component to render the currently selected move, instead of always rendering the final move:

If you click on any step in the game’s history, the tic-tac-toe board should immediately update to show what the board looked like after that step occurred.

Final cleanup

If you look at the code very closely, you may notice that xIsNext === true when currentMove is even and xIsNext === false when currentMove is odd. In other words, if you know the value of currentMove , then you can always figure out what xIsNext should be.

There’s no reason for you to store both of these in state. In fact, always try to avoid redundant state. Simplifying what you store in state reduces bugs and makes your code easier to understand. Change Game so that it doesn’t store xIsNext as a separate state variable and instead figures it out based on the currentMove :

You no longer need the xIsNext state declaration or the calls to setXIsNext . Now, there’s no chance for xIsNext to get out of sync with currentMove , even if you make a mistake while coding the components.

Wrapping up

Congratulations! You’ve created a tic-tac-toe game that:

  • Lets you play tic-tac-toe,
  • Indicates when a player has won the game,
  • Stores a game’s history as a game progresses,
  • Allows players to review a game’s history and see previous versions of a game’s board.

Nice work! We hope you now feel like you have a decent grasp of how React works.

Check out the final result here:

If you have extra time or want to practice your new React skills, here are some ideas for improvements that you could make to the tic-tac-toe game, listed in order of increasing difficulty:

  • For the current move only, show “You are at move #…” instead of a button.
  • Rewrite Board to use two loops to make the squares instead of hardcoding them.
  • Add a toggle button that lets you sort the moves in either ascending or descending order.
  • When someone wins, highlight the three squares that caused the win (and when no one wins, display a message about the result being a draw).
  • Display the location for each move in the format (row, col) in the move history list.

Throughout this tutorial, you’ve touched on React concepts including elements, components, props, and state. Now that you’ve seen how these concepts work when building a game, check out Thinking in React to see how the same React concepts work when build an app’s UI.

How do you like these docs?

JS Tutorial

Js versions, js functions, js html dom, js browser bom, js web apis, js vs jquery, js graphics, js examples, js references, json .parse().

A common use of JSON is to exchange data to/from a web server.

When receiving data from a web server, the data is always a string.

Parse the data with JSON.parse() , and the data becomes a JavaScript object.

Example - Parsing JSON

Imagine we received this text from a web server:

Use the JavaScript function JSON.parse() to convert text into a JavaScript object:

Make sure the text is in JSON format, or else you will get a syntax error.

Use the JavaScript object in your page:

Array as JSON

When using the JSON.parse() on a JSON derived from an array, the method will return a JavaScript array, instead of a JavaScript object.

Advertisement

Parsing Dates

Date objects are not allowed in JSON.

If you need to include a date, write it as a string.

You can convert it back into a date object later:

Convert a string into a date:

Or, you can use the second parameter, of the JSON.parse() function, called reviver .

The reviver parameter is a function that checks each property, before returning the value.

Convert a string into a date, using the reviver function:

Parsing Functions

Functions are not allowed in JSON.

If you need to include a function, write it as a string.

You can convert it back into a function later:

Convert a string into a function:

You should avoid using functions in JSON, the functions will lose their scope, and you would have to use eval() to convert them back into functions.

Get Certified

COLOR PICKER

colorpicker

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

[email protected]

Top Tutorials

Top references, top examples, get certified.

IMAGES

  1. React Native Tutorial for Beginners [Updated]

    html react tutorial

  2. Full React Tutorial #2

    html react tutorial

  3. React Tutorial for Beginners

    html react tutorial

  4. Code React Website Tutorial

    html react tutorial

  5. ReactJS Tutorial

    html react tutorial

  6. React Tutorials

    html react tutorial

VIDEO

  1. React JS-1

  2. ReactJS-5

  3. 🔥 Intro to React.JS

  4. ReactJS Top Best Practices #5

  5. Building a React Product Card Display from an API || #html #interview #reactjs #javascript

  6. Solve 1000+ Practice Problems on React, Node.js, Frontend and More!

COMMENTS

  1. Getting started with React

    Overview: Client-side JavaScript frameworks In this article we will say hello to React. We'll discover a little bit of detail about its background and use cases, set up a basic React toolchain on our local computer, and create and play with a simple starter app — learning a bit about how React works in the process. Hello React

  2. Quick Start

    Quick Start - React Quick Start. Learn how to use React, the library for web and native user interfaces, in a few easy steps. You will find tutorials, examples, and guides to help you create your first component, start a new project, or use built-in components and features.

  3. React Tutorial

    React Tutorial Home Next [+: React is a JavaScript library for building user interfaces. React is used to build single-page applications. React allows us to create reusable UI components. Start learning React now Learning by Examples Our "Show React" tool makes it easy to demonstrate React. It shows both the code and the result.

  4. How to Get Started With React

    React (also known as React.js or ReactJS) is a free and open-source front-end JavaScript library for creating UI component-based user interfaces. React is maintained by Meta (previously Facebook) along with a community of individual developers and organizations.

  5. Tutorial: Intro to React

    What Are We Building? In this tutorial, we'll show how to build an interactive tic-tac-toe game with React. You can see what we'll be building here: Final Result. If the code doesn't make sense to you, or if you are unfamiliar with the code's syntax, don't worry! The goal of this tutorial is to help you understand React and its syntax.

  6. Getting Started

    When starting a React project, a simple HTML page with script tags might still be the best option. It only takes a minute to set up! As your application grows, you might want to consider a more integrated setup. There are several JavaScript toolchains we recommend for larger applications.

  7. Introduction to React

    Initial Release to the Public (V0.3.0) was in July 2013. React.JS was first used in 2011 for Facebook's Newsfeed feature. Facebook Software Engineer, Jordan Walke, created it. Current version of create-react-app is v5.0.1 (April 2022). create-react-app includes built tools such as webpack, Babel, and ESLint.

  8. React for Beginners

    Flavio Copes React is one of the most popular JavaScript frameworks ever created, and I believe that it's one of the best tools out there. The goal of this handbook is to provide a starter guide to learning React. At the end of the book, you'll have a basic understanding of: What React is and why it's so popular How to install React

  9. The Complete React Tutorial for 2021

    Welcome to the complete React tutorial for 2021. This guide should help you become effective with React as quickly as possible as you build a complete application along the way. Compared to many tutorials you might have gone through before, this one is meant to be thoroughly practical from start to finish.

  10. React

    React is a powerful and popular library for creating web and native user interfaces. With React, you can build reusable components in JavaScript and combine them easily. Learn more about React's features, tutorials, and examples on the official website.

  11. React Tutorial

    Join more than 200,000 learners across all courses. React Tutorial is the easiest, most interactive way to learn & practice modern React online. Learn in an interactive environment. Understand how React works not just how to build with React.

  12. React Getting Started

    The quickest way start learning React is to write React directly in your HTML files. W3Schools Spaces The easiest way to get started with creating HTML files is W3Schools Spaces! It is the perfect place to create, edit, and share your work with others! Get started for free

  13. React Tutorial for Beginners

    React JS Tutorial for Beginners - Learn React 18 with TypeScript and build awesome frontend app! - Want to learn more? Get my complete React mastery course: ...

  14. Complete Reactjs Tutorial for Beginners: Step-by-step Guide (Part 1)

    Stephen Gbolagade Posted on Mar 23, 2023 • Updated on Mar 29, 2023 Complete Reactjs Tutorial for Beginners: Step-by-step Guide (Part 1) # webdev # react # javascript # beginners If you're interested in learning Reactjs but don't know where to start, this step-by-step guide is for you.

  15. The Best React Tutorials

    The Best Tutorials for Learning React. freeCodeCamp has a React tutorial on YouTube that will teach you all the basics in just 5 hours. We also have a more in-depth intermediate React tutorial that teaches you how to build an entire social media React app using Firebase. It is 12 hours long, and if you follow along, you will learn a ton of the ...

  16. React Website Tutorial

    Learn how to build a React website from scratch in this tutorial. We will use React Hooks and React Router for this beginner React JS Project. The website is...

  17. React Tutorial App

    React Tutorial: The easiest way to learn & practice modern React online. React Tutorial: The easiest way to learn & practice modern React online. Provide accessibility feedback ... HTML CSS; JavaScript; The first 67 lessons and challenges are totally free; after that, you will be asked to upgrade (a one-time payment that gives you access for 5 ...

  18. React JSX

    JSX allows us to write HTML in React. JSX makes it easier to write and add HTML in React. Coding JSX JSX allows us to write HTML elements in JavaScript and place them in the DOM without any createElement () and/or appendChild () methods. JSX converts HTML tags into react elements.

  19. React Tutorial

    React Tutorial: This free React tutorial is designed for people who prefer to learn by doing. So if you are a beginner or advanced React developer, this tutorial will guide you through all the fundamentals to build any React app and master React development.

  20. Learn ReactJS

    ReactJS (aka React) is an open-source JavaScript-based user interface library. It is insanely popular in web development communities today. React Native is equally popular among mobile application developers. In this article, we will look at a complete roadmap to learn ReactJS.

  21. Tutorial: Tic-Tac-Toe

    The tutorial is divided into several sections: Setup for the tutorial will give you a starting point to follow the tutorial.; Overview will teach you the fundamentals of React: components, props, and state.; Completing the game will teach you the most common techniques in React development.; Adding time travel will give you a deeper insight into the unique strengths of React.

  22. React Render HTML

    React's goal is in many ways to render HTML in a web page. React renders HTML to the web page by using a function called createRoot () and its method render (). The createRoot Function The createRoot () function takes one argument, an HTML element.

  23. React Forms

    Just like in HTML, React uses forms to allow users to interact with the web page. Adding Forms in React You add a form with React like any other element: Example: Get your own React.js Server Add a form that allows users to enter their name:

  24. JSON.parse()

    Learn the basics of HTML in a fun and engaging video tutorial. Templates. We have created a bunch of responsive website templates you can use - for free! ... it to the world with W3Schools Spaces. Create a Server. Create your own server using Python, PHP, React.js, Node.js, Java, C#, etc. How To's. Large collection of code snippets for HTML ...