Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Typescript + Redux + Typescript Readonly Interfaces
// scaffolding
interface IPostState
extends Readonly<{
post: IPost | null;
isLoading: boolean;
}> {} // this has to be a Readonly interface as well.
// reducers
const INITIAL_STATE: IPostState = {
post: null,
isLoading: false,
};
function postReducer(state: IPostState = INITIAL_STATE, action): IPostState {
switch (action.type) {
case "FETCHED": {
return {
post: action.payload.post,
isLoading: false,
};
}
case "UPDATED_TITLE": {
return {
...state,
post: {
...state.post,
title: action.payload.title,
},
};
}
default: {
return state;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment