Skip to main content

TS Redux

Create TS Redux File Structure

switch acts as type guard

define interface per action

removes need for action types

add enum for action types

import Dispatch type definition from redux
import { Dispatch } from "redux";
import Action type
import { Action } from "../actions";

TS annotate dispatch action type

const searchRepo = (term: string) => async (dispatch: Dispatch<Action\>) => {
dispatch({
type: ActionType.SEARCH_REPO,
});
};

{ useSelector }

combineReducers

Create Typed Custom Hooks

References