erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12.01k stars 2.5k forks source link

TypeError: Invalid attempt to destructure non-iterable instance #1252

Open majidkarimizadeh opened 7 years ago

majidkarimizadeh commented 7 years ago

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

jdosullivan commented 7 years ago

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?

majidkarimizadeh commented 7 years ago

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 :)

chatzipan commented 7 years ago

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.

majidkarimizadeh commented 7 years ago

@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.

majidkarimizadeh commented 7 years ago

@jahmaiosullivan the clientMiddlware is here https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/redux/middleware/clientMiddleware.js

davidfurlong commented 7 years ago

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]