0

I'm going through and adding a feature to code that exists and learning it at the same time, so heads up if I'm missing something big.

So I have this function:

export const LoadGrid = () => {
      return dispatch => {
        something.GetData(agasdg, {
          'parameters',
        }) 
          .then(r => r.json())
          .then(json => {
            console.log(json);
            const parts = json.Rows.map(part => {
              return {
                 // Keys and stuff
              };
            });
            dispatch({
              type: Types.InventoryLocationMove.LOAD_GRID,
              payload: parts,
            });
          })
          .catch(err => console.log(err));
      };
    };

and then in another part of my program I have this to call it:

  <Button
    style={style}
    onPress={
      ({ GridData } = () => {
        return LoadGrid({ location });
      })
    }
  >

But it just gives GridData a null value and errors my app.

I know I'm missing some basic concept, and there's a lot more code but I can't exactly post it all here.

Thanks!

  • 1
    What you're missing is that `GetData` is **asynchronous**, and you can't return from an asynchronous call – adeneo Aug 15 '17 at 13:57
  • @adeneo And that would be the basic concept I'm missing, I'm gonna dig around the internet and learn some more, update my question if necessary. – William Fallon Aug 15 '17 at 14:00
  • See the duplicate, it has a ton of information on how basic asynchronicity works – adeneo Aug 15 '17 at 14:11

0 Answers0