---
title: "How To Use Redux with React Hooks"
description: "Use Redux with React Hooks: replace connect with useSelector and useDispatch, available since React Redux 7.1, and refactor a component step by step."
canonical: "https://www.trevorlasn.com/blog/how-to-use-redux-with-react-hooks"
author: "Trevor I. Lasn"
published: "2019-06-20"
last-updated: "2026-02-15"
topics: ["React"]
---

# How To Use Redux with React Hooks

Use Redux with React Hooks: replace connect with useSelector and useDispatch, available since React Redux 7.1, and refactor a component step by step.

By Trevor I. Lasn · Published 2019-06-20 · Updated 2026-02-15 · https://www.trevorlasn.com/blog/how-to-use-redux-with-react-hooks

With the release of React Redux 7.1.0, we can now use hooks, which offer a modern approach to working with React. Hooks help us write less code while achieving the same functionality. This means we can build our applications faster and more efficiently.

If you’re new to hooks, check out my earlier tutorial, [Demystifying React Hooks.](https://www.trevorlasn.com/blog/demystifying-react-hooks) It will give you a solid understanding of how hooks work.

###  Refactoring a Redux Component to Use Hooks
Let’s start with a simple Redux component that uses the traditional class-based approach. We’ll refactor it to use React hooks.

```jsx
import React, { Component } from "react";
import { connect } from "react-redux";
import { toggleSwitch } from "./UiReducer";

class Toggle extends Component {
  render() {
    const { ui, toggleSwitch } = this.props;
    return (
        <input
          type="checkbox"
          checked={ui.toggle}
          onChange={toggleSwitch}
        />
    );
  }
}

const mapStateToProps = ({ ui }) => ({
  ui
});

export default connect(
  mapStateToProps,
  { toggleSwitch }
)(Toggle);
```

### Step 1: Convert to a Functional Component

We’ll start by converting the class component to a functional component. This change makes the code shorter and more readable:

```jsx
import React from "react";

const Toggle = ({ ui, toggleSwitch }) => (
  <input
    type="checkbox"
    checked={ui.toggle}
    onChange={toggleSwitch}
  />
);

export default Toggle
```

In this version, we use a functional component instead of a class. We also directly destructure ui and toggleSwitch from the function parameters.

### Step 2: Use useSelector to Access State

To read the state from Redux, we use the useSelector hook:

```jsx
import React from "react";
import { useSelector } from 'react-redux';

const Toggle = () => {
  const ui = useSelector(state => state.ui);
  return (
    <input
      type="checkbox"
      checked={ui.toggle}
      onChange={toggleSwitch}
    />
  );
};

export default Toggle
```

Here, *useSelector* replaces *mapStateToProps*. It provides access to the Redux state directly.

### Step 3: Use *useDispatch* to Dispatch Actions

To dispatch actions, we use the useDispatch hook:

```jsx
import React from "react";
import { useSelector, useDispatch } from 'react-redux';

const Toggle = () => {
  const ui = useSelector(state => state.ui);
  const dispatch = useDispatch();

  const toggleSwitch = () => {
    dispatch({ type: 'TOGGLE' });
  };

  return (
    <input
      type="checkbox"
      checked={ui.toggle}
      onChange={toggleSwitch}
    />
  );
};

export default Toggle
```

With *useDispatch*, we can call dispatch to send actions. In this case, we dispatch the TOGGLE action when the checkbox is toggled.

Congratulations! You have successfully refactored your component from a class-based approach to using hooks. Be sure to test the component to make sure it works as expected.

> **Note:** Redux Toolkit (RTK) is now the official, recommended way to write Redux logic. It includes utilities like `createSlice` and `configureStore` that simplify the setup shown in this article. See [redux-toolkit.js.org](https://redux-toolkit.js.org/) for details.
