Fakultas Ilmu Komputer UI

ApplicationState.jsx 875 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React, { useReducer } from "react";
import AuthReducer, { initialState } from "./store/reducers/auth_reducer";
import * as ACTIONS from "./store/actions/actions";
import AuthContext from "./utils/contex";
import Routes from "./routes";
import Loader from "./component/Loader";

const ApplicationState = () => {
  const [stateAuthReducer, dispatchAuthReducer] = useReducer(
    AuthReducer,
    initialState()
  );

  const handleLogin = (profile) => {
    dispatchAuthReducer(ACTIONS.login(profile));
  };

  const handleLogout = () => {
    dispatchAuthReducer(ACTIONS.logout());
  };

  return (
    <div>
      <Loader />
      <AuthContext.Provider
        value={{
          ...stateAuthReducer,
          handleLogin,
          handleLogout,
        }}
      >
        <Routes />
      </AuthContext.Provider>
    </div>
  );
};
export default ApplicationState;