React is giving me the ultimate headache. It's literally impossible to configure CORS headers and I don't know why. Finally got it to properly pull from an API, but now it's throwing the cross origin garbage at me.
Make up your mind
@CJ101 wondering if you figured it out, and not sure if what I'm mentioning applies to you.
Basically wondering if you have something like this:
function MyComponent(props) {
const [data, setData] = useState(null);
useEffect(() => {
const data = /* fetch, error checking, etc */
setData(data);
// Sounds like you're logging in a location similar to here, aka right after fetch completes
})
// If you log here you'll know if data is available on first render
return <div>{data.map(/* element */)}</div>;
}
Code above basically makes a request, then renders `data` (might not be the exact order). Yet `data` is null until the request completes, and React will render before it completes.
I'm guessing you have an entirely diff situation so this prob doesn't help or you already know this lol
update: this crap is still killing me. Fixed the cors garbage, and it's back to not populating the page after I call the API. What gets me is that if I go to the API url, I get a nice pretty JSON output, when I go to the browser page, it spits it out into console, but it will always, always say that data.map is not a function, despite having fetched the data, even with useState/useEffect. It's a never-ending cycle and I cannot understand how people just get this to work right off the bat with the basic boilerplate examples.
@X27 Nono, I'm saying I had a react issue, which took forever, which gave way into a separate issue, which is not a react issue. I'm just frustrated because it's one thing after another. But, giving my requests the right headers in my react project seem to do absolutely nothing lmao
I'm really lost on how headers is a React issue since it's a client side library. Wouldn't this be a node/express/whatever server issue even if you're working with server side React?
@.:A-MAN:. I like all the libraries and frameworks available, but this problem is impossible to diagnose because I've done all the possible fixes that I know of. It's not even a React problem at this point
Please Login To Post
Reason why it doesn't work is below the code block
Basically wondering if you have something like this:
Code above basically makes a request, then renders `data` (might not be the exact order). Yet `data` is null until the request completes, and React will render before it completes.
I'm guessing you have an entirely diff situation so this prob doesn't help or you already know this lol