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 useModelState = require('stremio/common/useModelState');
const mapProfileState = (ctx) => {
return ctx.profile;
};
const map = (ctx) => ctx.profile;
const useProfile = () => {
const { core } = useServices();
const initProfileState = React.useCallback(() => {
const init = React.useCallback(() => {
const ctx = core.transport.getState('ctx');
return mapProfileState(ctx);
return map(ctx);
}, []);
const profile = useModelState({
model: 'ctx',
init: initProfileState,
map: mapProfileState
});
return profile;
return useModelState({ model: 'ctx', init, map });
};
module.exports = useProfile;