Register to get access to free programming courses with interactive exercises

Introduction JS: React Hooks

Toto fisherman react hooks

Hooks are a mechanism in React that allows you to work completely without classes. It doesn't bring anything new, but it makes it easier to reuse code to solve common problems. Currently, this is the main way to write React applications. But hooks don't replace classes entirely. Moreover, the React team doesn't plan to remove support for classes, and some things can't be done without classes. An example of how the useState hook works for storing the state:

// useState – built-in React hook
// To be discussed in more detail in the next lesson
import React, { useState } from 'react';

const Example = () => {
  // Example of a hook for working with the state
  const [count, setCount] = useState(0);

  return (
      <p>You clicked {count} time(s)</p>
      <button onClick={() => setCount(count + 1)}>
        Click me

Hooks are functions whose names usually begin with use. So they're easy to distinguish from any other functions. React has about 10 hooks built in, of which only a few are used regularly. The main ones are those that repeat the functionality of class components, such as working with state, side effects (lifecycle), context, and direct access to the Dom. We'll look at them throughout the course. Information on the remaining hooks can be found in the official documentation.

In addition to the built-in ones, you can find hundreds, if not thousands, of ready-made hooks for all purposes on the web. For example, the popular react-use has more than 115 hooks. Now, development in React has largely turned into the search and use of suitable hooks, which is good, you can focus on doing your important business, and worry less about inventing bicycles.

Recommended materials

  1. Plugin eslint-plugin-react-hooks

Hexlet Experts

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

About Hexlet learning process

For full access to the course you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
hours of theory

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing:">Bookmate</span>
<span class="translation_missing" title="translation missing:">Healthsamurai</span>
<span class="translation_missing" title="translation missing:">Dualboot</span>
<span class="translation_missing" title="translation missing:">Abbyy</span>
Suggested learning programs

From a novice to a developer. Get a job or your money back!

Frontend Developer icon
Development of front-end components for web applications
start anytime 10 months

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.