import { useReducer } from 'react'; import { localeCompare } from '../util/Locale'; import { nextState } from '../util/StateHelper'; export const userInitialState = { username: '', isCurrentUser: function (otherUsername) { return localeCompare(this.username, otherUsername) } }; export function userReducer(state, action) { switch (action.type) { case 'next': return nextState(state, action); default: throw Error('UserReducer: unknown action.type', action.type); } } export default function useUserReducer() { return useReducer(userReducer, userInitialState); }