Redux Without Boilerplate
Setting State in Redux Without Action Boilerplate
Disclaimer
Boilerplate Hell
this.setState({ title: "Reducks" })Paring Down Our Code
export type Post = {
title: string,
body: string
}
export interface PostState {
post: Post
}
export const initialPostState: PostState = {
post: {
title: "Redux State is Cool",
body: "We can change global state in Redux"
}
}
export default (state: PostState = initialPostState, action: PostAction): PostState => {
switch (action.type) {
case actions.POST_SET_TITLE:
const { title } = action.payload
return { ...state, post: { ...state.post, title } }
case actions.POST_SET_BODY:
const { body } = action.payload
return { ...state, post: { ...state.post, body } }
default:
return state
}
}Type Safety
I'm only using $p to cut down on the length of these references as much as possible. This saves 2 characters (two whole characters!!) over the word path

Examples
Looking Forward
Last updated