react-redux-universal-hot-example
react-redux-universal-hot-example copied to clipboard
TypeError: Invalid attempt to destructure non-iterable instance
HI... im new in this project...but when run the code like belove
export function showMessage() {
return {
type: SHOW_MESSAGE,
promise: (client) => client.get('/posts')
};
}
i get this error: TypeError: Invalid attempt to destructure non-iterable instance can anyone Helllllp Me??? tnx
The format for this doesn't seem correct to begin with. There should be an array of type rather than a single value. But the error you mentioned seems to be related to be related to not compiling down to ES5. Did you get a proper explanation of how the clientMiddleWare works?
i change some part of clientMiddlware and solve it...
// const [REQUEST, SUCCESS, FAILURE] = types;
const REQUEST = 'REQUEST';
const SUCCESS = 'SUCCESS';
const FAILURE = 'FAILURE';
i think i have some problem with my babel and somthing like that :)
Hi @majidkarimizadeh. I believe you should follow @jahmaiosullivan's advice and make your type an Array. In your case try something like the following, instead of changing the middleware.
export function showMessage() {
return {
types: [SHOW_MESSAGE, SHOW_MESSAGE_SUCCESS, SHOW_MESSAGE_FAIL],
promise: (client) => client.get('/posts')
};
}
Try giving all your fetch actions the same types pattern.
@chatzipan thanks for your answer... actually i use the type of Array for my type...but i get the same error
export function showData(){
return {
type:[REQUEST, SUCCESS, FAILURE],
promise: client => client.get('/posts')
}
}
just by changing the middleware i solved this error.
@jahmaiosullivan the clientMiddlware is here https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/redux/middleware/clientMiddleware.js
i change some part of clientMiddlware and solve it...
// const [REQUEST, SUCCESS, FAILURE] = types; const REQUEST = 'REQUEST'; const SUCCESS = 'SUCCESS'; const FAILURE = 'FAILURE'; i think i have some problem with my babel and somthing like that :)
It looks like babel is trying to destructure types in
const [REQUEST, SUCCESS, FAILURE] = types;
and is failing - check that your types
in your action creators are defined & have >=3 elements
type:[REQUEST, SUCCESS, FAILURE],
This is a typo, it should be types: [REQUEST, SUCCESS,FAILURE]