bruno/renderer/providers/App/index.js
2022-09-28 02:25:05 +05:30

36 lines
792 B
JavaScript

import React, { useEffect } from 'react';
import useIdb from './useIdb';
import { useDispatch } from 'react-redux';
import { refreshScreenWidth } from 'providers/ReduxStore/slices/app';
export const AppContext = React.createContext();
export const AppProvider = props => {
// boot idb
useIdb();
const dispatch = useDispatch();
useEffect(() => {
dispatch(refreshScreenWidth());
}, []);
useEffect(() => {
const handleResize = () => {
dispatch(refreshScreenWidth());
};
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return (
<AppContext.Provider {...props} value='appProvider'>
{props.children}
</AppContext.Provider>
);
};
export default AppProvider;