2017-12-27 15 views
0

API 호출로 내 앱의 initialData를 업데이트하려고합니다.API 호출로 initialData를 업데이트하려고합니다.

오류가 발생합니다. (0, _configureStore2.default)은 기능이 아닙니다.

export const eventsHasErrored = bool => ({ 
     type: 'EVENTS_HAS_ERRORED', 
     hasErrored: bool 
}) 

export const eventsIsLoading = bool => ({ 
     type: 'EVENTS_IS_LOADING', 
     isLoading: bool 
}) 

export const eventsFetchDataSuccess = events => ({ 
     type: 'EVENTS_FETCH_DATA_SUCCESS', 
     events 
}) 

export function eventsFetchData(url) { 
    return (dispatch) => { 
     dispatch(eventsIsLoading(true)); 
     fetch(url) 
      .then((response) => { 
       if (!response.ok) { 
        throw Error(response.statusText); 
       } 
       dispatch(eventsIsLoading(false)); 
       return response; 
      }) 
      .then((response) => response.json()) 
      .then((events) => dispatch(eventsFetchDataSuccess(items))) 
      .catch(() => dispatch(eventsHasErrored(true))); 
    }; 
} 

내 감속기는 다음과 같습니다 :

export function eventsHasErrored(state = false, action) { 
    switch (action.type) { 
     case 'EVENTS_HAS_ERRORED': 
      return action.hasErrored; 

     default: 
      return state; 
    } 
} 

export function eventsIsLoading(state = false, action) { 
    switch (action.type) { 
     case 'EVENTS_IS_LOADING': 
      return action.isLoading; 

     default: 
      return state; 
    } 
} 

export function events(state = [], action) { 
    switch (action.type) { 
     case 'EVENTS_FETCH_DATA_SUCCESS': 

       return { 
     ...state, 
     ...action.events, 
     }; 

     default: 
      return state; 
    } 
} 

export function calendarView(state = null, action) { 
    switch (action.type) { 
     case 'CALENDAR_VIEW': 
      return action.viewType; 

     default: 
      return state; 
    } 
} 

이 여기

내가 내 이벤트 데이터를 얻을 수있는 thunk을 사용하고

// app.js 
import { Provider } from 'react-redux' 
import configureStore from './config/configureStore'; 

import AppNavigation from './navigation' 
import { eventsFetchData } from './actions/events' 

const store = configureStore(); 

// dispatch action to get array of events for app 
store.dispatch(eventsFetchData()); 

export default class App extends Component { 
    render() { 
    return (
     <Provider store={store}> 
     <AppNavigation /> 
     </Provider> 
    ); 
    } 
} 

/REDUX 설정을 내 반응한다 내 가게 :

const initialState = { 
    eventsHasErrored: false, 
    eventsIsLoading: true, 
    events: [], 
    calendarView: 0 
}; 

const reduxLogger = createLogger(); 

const store = createStore(
    rootReducer, 
    initialState, 
    applyMiddleware(thunk, reduxPromise, reduxLogger) 
); 

export default store; 

initialState을 API 호출로 업데이트하는 가장 좋은 방법은 무엇입니까?

답변

0

시도 :

const store = createStore(
    rootReducer, 
    initialState, 
    applyMiddleware(thunk, reduxPromise, reduxLogger) 
); 

export default store; 
: 나는 이미 상점을 작성한 반환하고이 오류 메시지를 설명 할 수 있다고보기 때문이다

// app.js 
import { Provider } from 'react-redux' 
import store from './config/configureStore'; 

import AppNavigation from './navigation' 
import { eventsFetchData } from './actions/events' 

// dispatch action to get array of events for app 
store.dispatch(eventsFetchData()); 

export default class App extends Component { 
    render() { 
    return (
     <Provider store={store}> 
     <AppNavigation /> 
     </Provider> 
    ); 
    } 
}