Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react.js | how to get rid of cross-origin error in Codesandbox

IN FIREFOX: When I execute my code the typical error I should get is: "TypeError: Cannot read property 'setState' of undefined", instead I received a very weird cross-origin error.

Here is a screenshot of the error: http://prntscr.com/iwipnb enter image description here

Error A cross-origin error was thrown. React doesn't have access to the actual error object in development. See https://reactjs.org/docs/cross-origin-errors.html for more information.

here is my code: https://codesandbox.io/s/4885l37xrw

How can I avoid the cross-origin error in Codesandbox in FIREFOX?

EDIT1: I know what is the code bug (bind(this)). I'm looking for the cross-origin error firefox problem. Thanks

like image 243
lito Avatar asked Mar 26 '18 13:03

lito


People also ask

How do I remove Cors error in react JS?

set the request's mode to 'no-cors' to fetch the resource with CORS disabled. It states that there's a missing Access-Control-Allow-Origin header on the resource you requested.

How do you overcome Cors in react?

There are several ways we can overcome this issue: Make REST API calls from the same domain as xkcd. Edit the CORS settings of xkcd's server. Make REST API calls from our own backend server.

How do you save a react project in CodeSandbox?

To save your projects and forks, you will want to create a GitHub account and sign in. There is a sign-in button located on the very top right. This way you'll be able to save your sandboxes. You can click a button on the left panel to get a list of sandboxes saved under your account.

How do I download CodeSandbox files?

Download files directly from CodeSandbox CodeSandbox has a super handy download button on the menu bar in the top left-hand corner. Click this button to download all the files and folders from CodeSandbox to a ZIP file. Extract the ZIP file and copy the files into your project.


1 Answers

I have my server setup to support CORS and it's still giving me this error.

It looks like an issue with ReactJS if there is an error while processing a response from the server. In my case it was happening while trying to parse invalid response into JSON.

like image 84
Chand Avatar answered Sep 30 '22 01:09

Chand