mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
18 lines
510 B
JavaScript
18 lines
510 B
JavaScript
const React = require('react');
|
|
const { useRouteFocused } = require('stremio-router');
|
|
const { useServices } = require('stremio/services');
|
|
|
|
const useCoreEvent = (onEvent) => {
|
|
const { core } = useServices();
|
|
const routeFocused = useRouteFocused();
|
|
React.useLayoutEffect(() => {
|
|
if (routeFocused) {
|
|
core.on('Event', onEvent);
|
|
}
|
|
return () => {
|
|
core.off('Event', onEvent);
|
|
};
|
|
}, [routeFocused, onEvent]);
|
|
};
|
|
|
|
module.exports = useCoreEvent;
|