/
valslava
/
react-practice_project
Обзор
Документация
Войти
/
valslava
/
react-practice_project
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
hooks
src/context/alert/alertState.js
25 строк
656 B
valslava2
upgrade Alert comp using hooks
27 мар 2024, 00:47
27 мар 2024, 00:47
207e3be
Код
Авторство
О чём код?
import React, {useReducer} from "react" import { AlertContext } from "./alertContext" import { alertReducer } from "./alertReducer" import { HIDE_ALERT, SHOW_ALERT } from "../types" export const AlertState = ({children}) => { const [state, dispatch] = useReducer(alertReducer, null) const hide = () => dispatch({type: HIDE_ALERT}) const show = (text, type='secondary') => { dispatch({ type: SHOW_ALERT, payload:{type, text} }) } return ( <AlertContext.Provider value={{ hide, show, alert: state }}> {children} </AlertContext.Provider> ) }