Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-redux-typescript-guide

> 前端框架
Open source

The complete guide to static typing in "React & Redux" apps using TypeScript

13.3K stars0 likes3 views
WebsiteGitHub

About

The complete guide to static typing in "React & Redux" apps using TypeScript

Goals

  • Complete type safety (with --strict flag) without losing type information downstream through all the layers of our application (e.g. no type assertions or hacking with any type)
  • Make type annotations concise by eliminating redundancy in types using advanced TypeScript Language features like Type Inference and Control flow analysis
  • Reduce repetition and complexity of types with TypeScript focused complementary libraries

React, Redux, Typescript Ecosystem

  • typesafe-actions - Typesafe utilities for "action-creators" in Redux / Flux Architecture
  • utility-types - Collection of generic types for TypeScript, complementing built-in mapped types and aliases - think lodash for reusable types.
  • react-redux-typescript-scripts - dev-tools configuration files shared between projects based on this guide

Examples

  • Todo-App playground: Codesandbox
  • React, Redux, TypeScript - RealWorld App: Github | Demo

Playground Project

Check out our Playground Project located in the /playground folder. It contains all source files of the code examples found in the guide. They are all tested with the most recent version of TypeScript and 3rd party type-definitions (like @types/react or @types/react-redux) to ensure the examples are up-to-date and not broken with updated definitions (It's based on create-react-app --typescript).

Playground project was created so that you can simply clone the repository locally and immediately play around with all the component patterns found in the guide. It will help you to learn all the examples from this guide in a real project environment without the need to create complicated environment setup by yourself.

Contributing Guide

You can help make this project better by contributing. If you're planning to contribute please make sure to check our contributing guide: CONTRIBUTING.md

Funding

You can also help by funding issues. Issues like bug fixes or feature requests can be very quickly resolved when funded through the IssueHunt platform.

I highly recommend to add a bounty to the issue that you're waiting for to increase priority and attract contributors willing to work on it.

🌟 - New or updated section

Table of Contents

  • React Types Cheatsheet
    • React.FC<Props> | React.FunctionComponent<Props>
    • React.Component<Props, State>
    • React.ComponentType<Props>
    • React.ComponentProps<typeof XXX>
    • React.ReactElement | JSX.Element
    • React.ReactNode
    • React.CSSProperties
    • React.XXXHTMLAttributes<HTMLXXXElement>
    • React.ReactEventHandler<HTMLXXXElement>
    • React.XXXEvent<HTMLXXXElement>
  • React
    • Function Components - FC
      • - Counter Component
      • - Counter Component with default props
      • - Spreading attributes in Component
    • Class Components
      • - Class Counter Component
      • - Class Component with default props
    • Generic Components
      • - Generic List Component
    • Hooks
      • - useState
      • - useContext
      • - useReducer
    • Render Props
      • - Name Provider Component
      • - Mouse Provider Component
    • Higher-Order Components
      • - HOC wrapping a component
      • - HOC wrapping a component and injecting props
      • - Nested HOC - wrapping a component, injecting props and connecting to redux 🌟
    • Redux Connected Components
      • - Redux connected counter
      • - Redux connected counter with own props
      • - Redux connected counter via hooks
      • - Redux connected counter with redux-thunk integration
    • Context
      • ThemeContext
      • ThemeProvider
      • ThemeConsumer
      • ThemeConsumer in class component
  • Redux
    • Store Configuration
      • Create Global Store Types
      • Create Store
    • Action Creators 🌟
    • Reducers
      • State with Type-level Immutability
      • Typing reducer
      • Typing reducer with typesafe-actions
      • Testing reducer
    • Async Flow with redux-observable
      • Typing epics
      • Testing epics
    • Selectors with reselect
    • Connect with react-redux
      • Typing connected component
      • Typing useSelector and useDispatch
      • Typing connected component with redux-thunk integration
  • Configuration & Dev Tools
    • Common Npm Scripts
    • tsconfig.json
    • TSLib
    • ESLint
      • .eslintrc.js
    • Jest
      • jest.config.json
      • jest.stubs.js
    • Style Guides
      • react-styleguidist
  • FAQ
    • Ambient Modules
      • Imports in ambient modules
    • Type-Definitions
      • Missing type-definitions error
      • Using custom d.ts files for npm modules
    • Type Augmentation
      • Augmenting library internal declarations - using relative import
      • Augmenting library public declarations - using node_modules import
    • Misc
      • - should I still use React.PropTypes in TS?
      • - when to use interface declarations and when type aliases?
      • - what's better default or named exports?
      • - how to best initialize class instance or static properties?
      • - how to best declare component handler functions?
  • Tutorials & Articles
  • Contributors

Installation

Types for React & Redux

bash
npm i -D @types/react @types/react-dom @types/react-redux

"react" - @types/react
"react-dom" - @types/react-dom
"redux" - (types included with npm package)*
"react-redux" - @types/react-redux

*NB: Guide is based on types for Redux >= v4.x.x.

⇧ back to top


React Types Cheatsheet

React.FC<Props> | React.FunctionComponent<Props>

Type representing a functional component

typescript
const MyComponent: React.FC<Props> = ...

React.Component<Props, State>

Type representing a class component

typescript
class MyComponent extends React.Component<Props, State> { ...

React.ComponentType<Props>

Type representing union of (React.FC<Props> | React.Component<Props>) - used in HOC

typescript
const withState = <P extends WrappedComponentProps>(
  WrappedComponent: React.ComponentType<P>,
) => { ...

React.ComponentProps<typeof XXX>

Gets Props type of a specified component XXX (WARNING: does not work with statically declared default props and generic props)

typescript
type MyComponentProps = React.ComponentProps<typeof MyComponent>;

React.ReactElement | JSX.Element

Type representing a concept of React Element - representation of a native DOM component (e.g. `

); };

bash

[⟩⟩⟩ demo](https://piotrwitek.github.io/react-redux-typescript-guide/#fccounter)

[⇧ back to top](#table-of-contents)

### - Counter Component with default props

```tsx
import * as React from 'react';

type Props = {
  label: string;
  count: number;
  onIncrement: () => void;
};

// React.FC is unaplicable here due not working properly with default props
// https://github.com/facebook/create-react-app/pull/8177
export const FCCounterWithDefaultProps = (props: Props): JSX.Element => {
  const { label, count, onIncrement } = props;

  const handleIncrement = () => {
    onIncrement();
  };

  return (
    

  );
};

FCCounterWithDefaultProps.defaultProps = { count: 5 };

⟩⟩⟩ demo

⇧ back to top

- Spreading attributes in Component

typescript
import * as React from 'react';

type Props = React.PropsWithChildren<{
  className?: string;
  style?: React.CSSProperties;
}>;

export const FCSpreadAttributes: React.FC<Props> = (props) => {
  const { children, ...restProps } = props;

  return 
;
};

⟩⟩⟩ demo

⇧ back to top


Class Components

- Class Counter Component

typescript
import * as React from 'react';

type Props = {
  label: string;
};

type State = {
  count: number;
};

export class ClassCounter extends React.Component<Props, State> {
  readonly state: State = {
    count: 0,
  };

  handleIncrement = () => {
    this.setState({ count: this.state.count + 1 });
  };

  render() {
    const { handleIncrement } = this;
    const { label } = this.props;
    const { count } = this.state;

    return (
      

    );
  }
}

⟩⟩⟩ demo

⇧ back to top

- Class Component with default props

typescript
import * as React from 'react';

type Props = {
  label: string;
  initialCount: number;
};

type State = {
  count: number;
};

export class ClassCounterWithDefaultProps extends React.Component<
  Props,
  State
> {
  static defaultProps = {
    initialCount: 0,
  };

  readonly state: State = {
    count: this.props.initialCount,
  };

  handleIncrement = () => {
    this.setState({ count: this.state.count + 1 });
  };

  render() {
    const { handle

Issues· 99 open

View all issuesOpen on GitHub
  • #126

    Update react-styleguidist website

    enhancementdocsIssueHuntUpdated Jun 24, 2026
  • #97

    Add a section about Types global namespace

    sectionIssueHuntUpdated Jun 19, 2026
  • #42

    [Section] Scalable Application Structure

    sectionopen discussionIssueHuntUpdated Jun 19, 2026
  • #46

    suggestion: recompose examples

    sectionin progressUpdated Jun 16, 2026
  • #40

    [Section] Modelling async data with ADT

    sectionopen discussionIssueHuntUpdated Jun 15, 2026
  • #91

    Factory types for connect props

    enhancementIssueHuntUpdated Jun 9, 2026
  • #55

    suggestion: connected generic component

    enhancementIssueHuntUpdated May 29, 2026
  • #82

    Providing the motivation and how to use this guide

    docsIssueHuntUpdated May 29, 2026
  • #203

    `bindActionCreators` example is outdated

    Updated May 23, 2026
  • #212

    'fc-counter-connected-bind-action-creators.usage' component cannot work

    Updated May 23, 2026

> Tags

TypeScriptflowguideguidelinespatterns

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架