useProfile code shorten

This commit is contained in:
nklhrstv 2020-10-22 17:59:46 +03:00
parent 09be8bce0d
commit 13f58fcbff

View file

@ -4,22 +4,15 @@ const React = require('react');
const { useServices } = require('stremio/services'); const { useServices } = require('stremio/services');
const useModelState = require('stremio/common/useModelState'); const useModelState = require('stremio/common/useModelState');
const mapProfileState = (ctx) => { const map = (ctx) => ctx.profile;
return ctx.profile;
};
const useProfile = () => { const useProfile = () => {
const { core } = useServices(); const { core } = useServices();
const initProfileState = React.useCallback(() => { const init = React.useCallback(() => {
const ctx = core.transport.getState('ctx'); const ctx = core.transport.getState('ctx');
return mapProfileState(ctx); return map(ctx);
}, []); }, []);
const profile = useModelState({ return useModelState({ model: 'ctx', init, map });
model: 'ctx',
init: initProfileState,
map: mapProfileState
});
return profile;
}; };
module.exports = useProfile; module.exports = useProfile;