Shouldn’t recursion be prevented in React component?

I had an error recently while working with React/Next.js and styled-components. I was to create a styled component for one of my app’s regular components but accidentally gave it the same name.

This lead to an infinite loop in the browser. This is the…


This content originally appeared on DEV Community and was authored by Elijah Trillionz

I had an error recently while working with React/Next.js and styled-components. I was to create a styled component for one of my app's regular components but accidentally gave it the same name.

This lead to an infinite loop in the browser. This is the first time I have experienced such error in React, and my problem was that there was no hint whatsoever as to what is wrong.

ESLint in webstorm wouldn't call it an error, because recursion do exists and it's not an error.

So I was thinking, is there no way React or should I say Next.js could have failed while compiling.

I know recursion can exist and isn't and shouldn't be logged as an error, but then should recursion exist in React?
How does calling a component inside of that component do something useful? I don't know if you guys do anything like that? Please share what you do with it.

My point is, if there is really no point of having a component inside of itself, then why not throw an error if that happens!


This content originally appeared on DEV Community and was authored by Elijah Trillionz


Print Share Comment Cite Upload Translate Updates
APA

Elijah Trillionz | Sciencx (2022-02-10T20:38:25+00:00) Shouldn’t recursion be prevented in React component?. Retrieved from https://www.scien.cx/2022/02/10/shouldnt-recursion-be-prevented-in-react-component/

MLA
" » Shouldn’t recursion be prevented in React component?." Elijah Trillionz | Sciencx - Thursday February 10, 2022, https://www.scien.cx/2022/02/10/shouldnt-recursion-be-prevented-in-react-component/
HARVARD
Elijah Trillionz | Sciencx Thursday February 10, 2022 » Shouldn’t recursion be prevented in React component?., viewed ,<https://www.scien.cx/2022/02/10/shouldnt-recursion-be-prevented-in-react-component/>
VANCOUVER
Elijah Trillionz | Sciencx - » Shouldn’t recursion be prevented in React component?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/10/shouldnt-recursion-be-prevented-in-react-component/
CHICAGO
" » Shouldn’t recursion be prevented in React component?." Elijah Trillionz | Sciencx - Accessed . https://www.scien.cx/2022/02/10/shouldnt-recursion-be-prevented-in-react-component/
IEEE
" » Shouldn’t recursion be prevented in React component?." Elijah Trillionz | Sciencx [Online]. Available: https://www.scien.cx/2022/02/10/shouldnt-recursion-be-prevented-in-react-component/. [Accessed: ]
rf:citation
» Shouldn’t recursion be prevented in React component? | Elijah Trillionz | Sciencx | https://www.scien.cx/2022/02/10/shouldnt-recursion-be-prevented-in-react-component/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.