0

I have the following fetch call in a React app on codesandbox : https://codesandbox.io/s/react-fetch-example-for-so-vxxie

If I activate either line

.then(console.log(data))

or

loadOptions={this.state.data}

I get : A cross-origin error was thrown. React doesn't have access to the actual error object in development. See https:// fb.me/react-crossorigin-error for more information.

Why and how to troubleshoot this ?

(please note I added a space in front of fb.me to pass validation here on StackOverflow)

Jérôme Oudoul
  • 369
  • 1
  • 5
  • 14

1 Answers1

0

Not sure exactly from what universe the error message comes from, but .then(console.log(data)) cannot work, because data is not defined. You would rather want

.then(data => console.log(data))

and still the next .then would fail because it requires the result from the above to perform its task, so you'd do this, which works for me in your sandbox example:

.then(data => { console.log(data); return data; })
JulienD
  • 7,102
  • 9
  • 50
  • 84
  • Thank you @JulienD Your answer helped me move on and I was able to make the whole example work eventually using react-select v3 : https://codesandbox.io/s/react-select-v3-asyncselect-fetch-ewlib – Jérôme Oudoul Jun 16 '19 at 19:37