Comments (7)
@nbrignol Why are you trying to write a hook as a class? There's no reason to.
from react.
@nbrignol you are returning react hooks from the class based component that in itself breaking the reack hook rules. Let us know your usecase we will try to help you with that.
from react.
@nbrignol Why are you trying to write a hook as a class? There's no reason to.
Because I want to :p. Class methods are functions, right ?
And in this case because classes are great for abstractions : I can abstract my hook behind an interface for exemple.
Actually this is working very well. The problems comes from the linter's message that is not right.
If it's forbidden (I'd like to know why and) the message should be dedicated : this is not a class component.
And if it's not (what I think and hope) the message should not be triggered here.
from react.
@nbrignol there is genuinely no good reason to do this that I can think of. There's no benefit. A hook doesn't need to be "abstracted behind an interface". It shouldn't have access to class field methods. It needs to be based solely on the inputs and calling other hooks.
You're running into a problem you've created for yourself :) Just write it as a normal standalone function and move on.
from react.
@nbrignol there is genuinely no good reason to do this that I can think of. There's no benefit. A hook doesn't need to be "abstracted behind an interface". It shouldn't have access to class field methods. It needs to be based solely on the inputs and calling other hooks.
You're running into a problem you've created for yourself :) Just write it as a normal standalone function and move on.
Again I think this is not the point.
Either it's a technical limitation and can't do that : I can understand, and I think you should add a dedicated message because this one does not match the context;
or it's not a problem in itself (even if is not a traditional way to work) and the error should not be triggered.
In both case, ESLint doesn't handle well this situation, that's why I am filling this "bug".
(Of course I understand this is not a priority matter for the project !)
Thanks for your time.
from react.
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
from react.
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!
from react.
Related Issues (20)
- Bug [React-DOM]: Missing "bun" export field in package.json HOT 3
- Bug: Spurious warnings in react dev runtime about using "key" property in spread object
- [React 19] React warns about "fetchpriority" props HOT 10
- Bug: Uncaught TypeError: Cannot read properties of null (reading 'useMemo') [React 18.3.1] HOT 6
- Bug: Warning: React does not recognize the `fetchPriority` prop on a DOM element [React 18.3.1] HOT 2
- [React 19] react-reconciler README is missing scheduler and form hooks
- [DevTools Bug]: React 17 error while trying to inspect hooks "Context reads do not line up with context dependencies." HOT 7
- `react-server-dom-webpack/node-register` not finding directives in IIFEs
- spam
- Update react GitHub page CNAME record HOT 2
- Publish React on JSR
- Bug: When setState is called with the same value as before, memory goes up
- [DevTools Bug]: Newline in component key string will look odd in component tree HOT 2
- [React 19] HOT 1
- [React 19] prop-types removal alternative / console component trace HOT 6
- [React 19] Issue with server action "use server" and exported error (Maybe NextJS) HOT 2
- react devtools版本5.0之后,点击Open in editor时,不能跳转到vscode对应文件的行 HOT 1
- After react devtools version 5.0, when you click Open in editor, you cannot jump to the line of the file corresponding to vscode
- Bug: unexpected Warning: `ReactDOMTestUtils.act` is deprecated in favor of `React.act`. HOT 10
- [React+19] HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.