import { useReducer } from 'react'; import { localeCompare } from '../util/Locale'; const initialState = { username: '', isCurrentUser: function (otherUsername) { return localeCompare(this.username, otherUsername) } }; function reducer(state, action) { switch (action.type) { case 'parse': return { ...state, username: action.userJson.holdingIdentity.name }; default: throw Error('UserReducer: unknown action.type', action.type); } } export default function useUserReducer() { return useReducer(reducer, initialState); }