DEV Community

Osman Zakir
Osman Zakir

Posted on

I have an "Unreachable Code Detected" Error in my React app - How to fix?

Hi, everyone. I have this GitHub repository that I made for the source code for my solution to this project on FreeCodeCamp.

I have an error that says "Unreachable Code Detected", on lines 245 to 252 of my JS file. Why is it flagged as "unreachable code" and how do I fix it?

Also, right now nothing is being rendered when I run the code (aside from FreeCodeCamp's testable project script output). I don't get how I could fix this problem, either.

Top comments (3)

Collapse
 
shane profile image
Shane McGowan • Edited

Unreachable code is quite literally code that cannot be reached at any point while executing. This could be cause by an if statement that will never evaluate to true or a function returning or throwing an error early on in a function meaning any code after that will never be executed

I'm not familiar with react but it looks like your issue is the bit after your /> tag shouldn't be there, but I'm not sure

Collapse
 
justusburger profile image
Justus Burger

The first problem I can see is that line 241-252 should be wrapped in a fragment.

return (
<>

...
</>
);

Collapse
 
dragonosman profile image
Osman Zakir • Edited

Thanks for the reply.

Could you explain, please? Why does putting it in a Fragment solve the issue?

I fixed all of the errors I was getting (aside from errors about unused symbols, but those understandable), but I still can't get anything to appear in the browser. Why? How do I fix this? I've made another post about this too.