mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-26 01:44:05 +01:00
36 lines
792 B
JavaScript
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;
|