Использую Flow в проекте.
Фот как выглядит пример Апп редусера.
//@flow
import type {
ActionWithPayloadType,
AppStateType
} from '@project/types';
import { OPEN_MODAL, CLOSE_MODAL, SET_USER_LOGIN } from '../constants';
const initialState: AppStateType = {
isModalOpen: false,
isUserLoggedIn: false
};
//eslint-disable-next-line complexity
const appReducer = (
state: AppStateType = initialState,
action: ActionWithPayloadType = { type: '', payload: '' }
) : AppStateType => {
if (!action) { return state; }
if (action.type === OPEN_MODAL) {
return { ...state, isModalOpen: true };
}
if (action.type === CLOSE_MODAL) {
return { ...state, isModalOpen: false };
}
if (action.type === SET_USER_LOGIN) {
return { ...state, isUserLoggedIn: action.payload };
}
return state;
};
export default appReducer;
@project/types
export type ActionWithPayloadType = {
type: string,
payload: *
};
export type AppStateType = {
isModalOpen: boolean,
isUserLoggedIn: boolean
}