Skip to content

Instantly share code, notes, and snippets.

@khades
Created January 10, 2020 14:14
Show Gist options
  • Save khades/516b7427c24fc65a4b3a6ce075842e50 to your computer and use it in GitHub Desktop.
Save khades/516b7427c24fc65a4b3a6ce075842e50 to your computer and use it in GitHub Desktop.
import * as actionTypes from "./actionTypes";
export function dispatchFirstAction(payload: string) {
return {
type: actionTypes.FirstAction,
payload
};
}
export function dispatchSecondAction(payload: number) {
return {
type: actionTypes.SecondAction,
payload
};
}
import * as actionCreators from "./actionCreators";
import * as actionTypes from "./actionTypes";
export type InferValueTypes<T> = T extends { [key: string]: infer U }
? U
: never;
type State = { value: string };
export default function reducer(
state: State = { value: "hello" },
action: ReturnType<InferValueTypes<typeof actionCreators>>
): State {
switch (action.type) {
case actionTypes.FirstAction:
return { value: action.payload };
case actionTypes.SecondAction:
return { value: state.value + action.payload };
default:
return state;
}
}
export const FirstAction = "TestReducer/FirstAction" as const;
export const SecondAction = "TestReducer/SecondAction" as const;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment