{"size": 836, "ext": "js", "max_stars_repo_path": "src/utils/useDashboardContext.js", "max_stars_repo_name": "kev-luo/ping-client", "max_stars_repo_stars_event_min_datetime": "2021-01-14T18:52:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T18:52:42.000Z", "max_issues_repo_path": "src/utils/useDashboardContext.js", "max_issues_repo_name": "kev-luo/ping-client", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/useDashboardContext.js", "max_forks_repo_name": "kev-luo/ping-client", "max_forks_repo_forks_event_min_datetime": "2020-12-02T18:08:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-02T18:08:35.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 20.9, "max_line_length": 76, "alphanum_fraction": 0.6555023923}
import React, { useContext, useReducer } from "react";
import Actions from "./dashboardActions";

const DashboardContext = React.createContext({
  selectedUser: null,
});

const initialState = {
  selectedUser: null,
};

function reducer(state, { type, payload }) {
  switch (type) {
    case Actions.SELECT_USER:
      return {
        ...state,
        selectedUser: payload,
      };
    case Actions.CLEAR_USER:
      return {
        ...state,
        selectedUser: null,
      };
    default:
      return state;
  }
}

function DashboardProvider(props) {
  const [state, dispatch] = useReducer(reducer, initialState);

  return <DashboardContext.Provider value={{state, dispatch}} {...props} />;
}

const useDashboardContext = () => {
  return useContext(DashboardContext);
};

export { useDashboardContext, DashboardProvider };
