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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.