mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-08-18 09:27:02 +00:00
useNotifications hook implemented
This commit is contained in:
parent
e35fefd414
commit
10e7e98dd7
1 changed files with 27 additions and 0 deletions
27
src/common/NavBar/NotificationsMenu/useNotifications.js
Normal file
27
src/common/NavBar/NotificationsMenu/useNotifications.js
Normal 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;
|
||||
Loading…
Reference in a new issue