corda-checkers/webapp/src/reducer/user.js
2023-11-16 18:19:40 +01:00

28 lines
584 B
JavaScript

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);
}