/
valslava
/
react-practice_project
Обзор
Документация
Войти
/
valslava
/
react-practice_project
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
hooks
src/context/github/githubReducer.js
17 строк
669 B
valslava2
create github hooks, getting users data from github api
27 мар 2024, 23:38
27 мар 2024, 23:38
9048d18
Код
Авторство
О чём код?
import { CLEAR_USERS, GET_REPOS, GET_USER, SEARCH_USERS, SET_LOADING } from "../types" const handlers = { [SEARCH_USERS]: (state, action) => ({...state, users: action.payload, loading: false}), [GET_REPOS]: (state, action) => ({...state, repos: action.payload, loading: false}), [GET_USER]: (state, action) => ({...state, user: action.payload, loading: false}), [SET_LOADING]: (state) => ({...state, loading: true}), [CLEAR_USERS]: (state) => ({...state, users: []}), DEFAULT: state => state } export const githubReducer = (state, action) => { const handler = handlers[action.type] || handlers.DEFAULT return handler(state, action) }