NISHIO Hirokazu[Translate]
Redux化
こんな感じですかね。 Redux+TypeScript

ts
import { createStore } from 'redux'; ... export const initialState = { ... }; export type StateType = typeof initialState; enum ActionType { SET_ITEMS = "SET_ITEMS", } export const setItems = (items: StateItem[]) => { return { type: ActionType.SET_ITEMS, payload: items } } interface Action { type: ActionType; payload: any; } function rootReducer(state = initialState, action: Action) { switch (action.type) { case ActionType.SET_ITEMS: return { ...state, items: action.payload }; default: return state; } } export const store = createStore(rootReducer);


"Engineer's way of creating knowledge" the English version of my book is now available on [Engineer's way of creating knowledge]

(C)NISHIO Hirokazu / Converted from [Scrapbox] at [Edit]