Похожие чаты

And you added the provider for it somewhere?

1 ответов

6 просмотров

import React, { useReducer } from "react" import axios from "axios" import BGTContext from "./bgtContext" import BGTReducer from "./bgtReducer" import { GET_COLLECTION, GET_SECTIONS, SET_LOADING } from "../types" const BGTState = props => { const initialState = { sections: [], collection: {}, loading: false, } const [state, dispatch] = useReducer(BGTReducer, initialState) // Ottiene le sezioni della navbar const getSections = async () => { try { setLoading() const res = await axios.get( ${process.env.API_URL}/sections?_sort=order:ASC ) dispatch({ type: GET_SECTIONS, payload: res.data, }) } catch (err) { dispatch({ type: GET_SECTIONS, payload: err.response.msg, }) } } // Ottiene la collezione tramite il riferimento const getCollection = async id => { try { setLoading() const res = await axios.get(${process.env.API_URL}/collections/${id}) dispatch({ type: GET_COLLECTION, payload: res.data, }) } catch (err) { console.log(err) } } const setLoading = () => dispatch({ type: SET_LOADING }) return ( <BGTContext.Provider value={{ sections: state.sections, loading: state.loading, collection: state.collection, getSections, getCollection, }} > {props.children} </BGTContext.Provider> ) } export default BGTState

Похожие вопросы

Обсуждают сегодня

Any got any price predictions for hbar this bull run ?
Crypto_learn2Earn_Official
32
Всех приветствую! Хочу поставить Linux Mint на ноут с Win10. Есть неясности по начальному созданию разделов диска на этапе установки, поскольку на разных ресурсах дают соверше...
Konstantin
9
какие клиентские датасеты в лазаре умеют объединяться в master-detail? нужно забрать на клиент запись из одной таблицы и выборку из другой связанной один-ко-многим, отредактир...
Igor
19
What about KDS, they announced a big improvement at the beginning of 2024 and still nothing. Apparently the delay is linked to Kadena core... Problem of grant or something oth...
ORAxies.bit
17
Why is kda better than kaspa?
Gakob
40
А как старый хаскел с новым стыковать ? потому как тут работает https://play.haskell.org/saved/C3xpMzcd, а вот тут https://stepik.org/lesson/7602/step/9?unit=1473 нет ошибка C...
Fedor
131
Подскажите, сейчас что то есть (JS модуль какой-нибудь), что можно использовать для: 1) переваривания javascript codа из html fileа, т.е. разбивки, на переменные, команды, бло...
Iar De
32
Девелоперы, к вам вопрос. Почему так плохо с поддержкой mysql, mariadb и относящихся к ним пакетам?
Perfect Gentleman
21
Мне интересно, скорее людей здесь используют D, Rust, C/C++ для решения реальных прикладных задач за деньги?)
Evil Satanson
43
But it Was said we get the tokens now just not the staking rewards ?
IneedMoney🤑 MaN
17
Карта сайта