2022-09-07 21:21:45 +00:00
|
|
|
import { useContext, useState, useEffect } from 'react';
|
|
|
|
import { AppContext } from 'context/AppContext';
|
|
|
|
import { useNavigate } from 'react-router-dom'
|
|
|
|
|
|
|
|
export function useRoot() {
|
|
|
|
|
|
|
|
const [state, setState] = useState({});
|
|
|
|
const app = useContext(AppContext);
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
const updateState = (value) => {
|
|
|
|
setState((s) => ({ ...s, ...value }));
|
|
|
|
}
|
|
|
|
|
2023-02-15 23:47:18 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (app.state.session === true) {
|
|
|
|
navigate('/session');
|
|
|
|
}
|
|
|
|
if (app.state.session === false) {
|
|
|
|
navigate('/login');
|
|
|
|
}
|
|
|
|
}, [app.state]);
|
|
|
|
|
2022-09-07 21:21:45 +00:00
|
|
|
const actions = {
|
|
|
|
};
|
|
|
|
|
|
|
|
return { state, actions };
|
|
|
|
}
|
|
|
|
|