Can't use recursive component
See original GitHub issueDescribe the bug
When I try to use a recursive component (a component that imports itsefl) I get the following error :
RecursiveComponent.vue:9 Uncaught ReferenceError: Cannot access 'RecursiveComponent' before initialization
Reproduction
Repo here : https://github.com/nicolas-t/bug-report-vite-recursive-component
Steps to reproduce :
yarn install
yarn dev
- Open browser’s console to see the error
System Info
vite
version: 2- Operating System: Ubuntu
- Node version: 12.18.2
- Package manager (npm/yarn/pnpm) and version: yarn 1.22
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
can't use recursive map in react component - Stack Overflow
To support the nested data with recursion, I've created a function with returns an input for every key, value pair in the data....
Read more >Recursive components in React: A real-world example
In this article, we will explore the details of recursive components in React and their usage in a real-world application.
Read more >Shouldn't recursion be prevented in React component?
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...
Read more >Recursive React Components: A real world example - YouTube
In this video we go over how to use recursive Reactjs components to display comments on rib.gg! ... Your browser can't play this...
Read more >How to Use Recursion in React - freeCodeCamp
What will happen is, the function or the component will be called as long as we have the data. So, let's try to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The self-importing syntax, although works, doesn’t mean you can eagerly access the imported binding:
Here it will result in the same error in the browser over a vanilla http server because
foo
is accessed before the module itself can be initialized.However this will work:
But again, this is
< RecursiveComponent>
and it just works)FYI you don’t need to do this. In Vite Vue SFCs can implicitly reference themselves by file name (without
.vue
extension).