Это мой store.js :
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { createLogger } from 'redux-logger';
import mainReducer from './reducers/index';
import fetchJokes from './actions/jokes';
const loggerMiddleware = createLogger();
const store = createStore(
mainReducer,
applyMiddleware(
thunkMiddleware,
loggerMiddleware
)
)
store
.dispatch(fetchJokes(1))
.then(() => console.log(store.getState()))
export default store
, а это мой / actions / jokes.js
import fetch from 'cross-fetch';
import { REQUEST_JOKES, RECEIVE_JOKES } from '../types/jokes'
/*synchronous actions*/
export const requestJokes = quantity => ({
type: REQUEST_JOKES,
quantity
});
export const receiveJokes = data => ({
type: RECEIVE_JOKES,
jokes: data.value.map(j => j.joke)
});
/*asynchronous actions*/
export const fetchJokes = quantity => {
return dispatch => {
dispatch(requestJokes(quantity))
return fetch('https://api.icndb.com/jokes/random/${quantity}')
.then(response => response.json(),
error => console.log('An error: ', error))
.then(data => dispatch(receiveJokes(data)))
}
}
И консоль приносит мне ошибку Uncaught TypeError: (0 , _jokes2.default) is not a function
.Я исследовал проблему с действием fetchJokes
, но что за проблема с этой функцией, я не могу распознать.