useNotifications hook implemented

This commit is contained in:
svetlagasheva 2019-10-15 17:06:41 +03:00
parent e35fefd414
commit 10e7e98dd7

View file

@ -0,0 +1,27 @@
const React = require('react');
const { useServices } = require('stremio/services');
const useNotifications = () => {
const [notifications, setNotifications] = React.useState([]);
const { core } = useServices();
React.useEffect(() => {
const onNewState = () => {
const state = core.getState();
setNotifications(state.notifications.groups);
};
core.on('NewModel', onNewState);
core.dispatch({
action: 'Load',
args: {
load: 'Notifications',
args: { extra: [] }
}
});
return () => {
core.off('NewModel', onNewState);
};
}, []);
return notifications;
};
module.exports = useNotifications;