Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Studio React template project doesn't work with hook based components - Error: Invalid hook call #40631

Closed
xuhaohems opened this issue Mar 10, 2022 · 5 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-spa ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@xuhaohems
Copy link

I am using the React web application template in Visual Studio 2022 to create a web project. Right after project is created, I installed a component that’s implemented with hooks, e.g. React-Bootstrap by package management command -
npm install react-bootstrap [email protected]

Then I import it to home.js -

import Button from ‘react-bootstrap/Button’;
and add an element -

Button #1 Button #2 Button #3
Run the project and I get the following error -

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

I haven’t added any other code and I think there is something wrong with the code in the template but I can’t figure out the issue.

@Pilchie
Copy link
Member

Pilchie commented Mar 10, 2022

Hi - this doesn't seem to be an ASP.NET Core question, but rather something about react. Unfortunately, that's outside the scope of our team.

Can you say exactly which template title you created?

@Pilchie Pilchie added External This is an issue in a component not contained in this repository. It is open for tracking purposes. Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Mar 10, 2022
@ghost
Copy link

ghost commented Mar 10, 2022

Hi @xuhaohems. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@xuhaohems
Copy link
Author

This is about the ASP.Net Core with React.js template (C#)
The template generated can't work with any hook based component. You can follow the step to repro the issue.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Mar 10, 2022
@Pilchie
Copy link
Member

Pilchie commented Mar 10, 2022

Thanks for confirming. Unfortunately, our team are not react developers, and can't really help debug issues with the react part of the template. We mostly just take the output of a new react project and add it to the template.

@Pilchie Pilchie added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Mar 10, 2022
@javiercn
Copy link
Member

Our templates are a starting point and you can choose to modify them to use new features as needed. In this case, hooks seem to be incompatible with the default style of the templates (which is class based components). You can feel free to change the code to use function components and leverage hooks, but that is not something we plan to do.

@javiercn javiercn added ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. feature-spa question and removed External This is an issue in a component not contained in this repository. It is open for tracking purposes. labels Mar 10, 2022
@ghost ghost added the Status: Resolved label Mar 10, 2022
@javiercn javiercn removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Mar 10, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-spa ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants