Реагировать Большой календарь Axios Firebase - PullRequest
0 голосов
/ 11 октября 2019

Я хочу задать запрос GET React Big Calendar axios для базы данных firebase в моем приложении, но я получаю ошибку. Все, кроме метода GET, похоже, работает (ADD, UPDATE, REMOVE).

Action.js

export function getEvents()
{
    const request = axios.get('https://dbname.firebaseio.com/events.json?auth=AUTH_KEY');

     return (dispatch) =>
    request.then((response) =>
        dispatch({
            type   : GET_EVENTS,
            payload: response.data
        })
    );
}

Reducer.js

const eventsReducer = function (state = initialState, action) {
    switch ( action.type )
    {
        case Actions.GET_EVENTS:
        {
            const entities = action.payload.map((event) => (
                {
                    ...event,
                    start: new Date(event.start),
                    end  : new Date(event.end)
                }
            ));

            return {
                ...state,
                entities
            };
        }

Это то, что я получаю

action.payload.map не является функцией

  16 | {
  17 |     case Actions.GET_EVENTS:
  18 |     {
> 19 |         const entities = action.payload.map((event) => (  
  20 |             {
  21 |                 ...event,
  22 |                 start: new Date(event.start),

Здесь приведен пример работы функции newEvent.

export function addEvent(newEvent)
{
    return (dispatch, getState) => {

        const request = axios.post('https://dbname.firebaseio.com/events.json?auth=AUTH_KEY', {
            newEvent
        });

        return request.then((response) =>
            Promise.all([
                dispatch({
                    type: ADD_EVENT
                })
            ]).then(() => dispatch(getEvents()))
        );
    };
}

Чтобы проверить ответные данные из axios, я использовал этот код:

 const isAuthenticated = () => { 
    return axios.get('https://dbname.firebaseio.com/events.json?auth=AUTH_KEY').then(response => {
        return response.data
      }).catch(error => console.log(error));
 };

 isAuthenticated().then(data => {
    console.log({ message: 'Request received!', data })
  })

и получил:

data: {…}
​​
"-LquZyxOjMmOaHC2fC0a": {…}
​​​
newEvent: {…}
​​​​
allDay: true
​​​​
desc: "qweqeasd"
​​​​
end: "2019-10-11T11:28:35.754Z"
​​​​
id: "ba792e4f"
​​​​
start: "2019-10-11T11:28:35.754Z"
​​​​
title: "qwe"
​​​​
<prototype>: Object { … }
​​​
<prototype>: Object { … }
​​
<prototype>: Object { … }
​
message: "Request received!"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...