Comments (5)
@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.
Related Issues (20)
- Bug: react.dev tutorial-tic-tac-toe sample project errors out in modern node versions HOT 20
- Feature request: TODO task HOT 2
- Request: Add a LICENSE file to the `client-only` package HOT 9
- [DevTools Bug]: TypeError: Cannot read properties of undefined (reading 'forEach') HOT 12
- bypass progressive loading for the CSS HOT 6
- Bug: hydration fails when using Promise values with React Server Components HOT 2
- Bug: Re-rendering dynamically nested createElement() unmounts children HOT 2
- React Way to Make Immediate Changes on DOM HOT 1
- [React: re-render]: On changing search value: it re-render the whole component HOT 4
- Bug: some /public resources not served when proxy is enabled in manifest. HOT 3
- Bug: No apparent way to debug setupProxy.js HOT 3
- Bug: useEffect not firing when depending on hook value HOT 2
- Bug: HOT 1
- Anisha wants to pay 0 USD to have this issue fixed
- Bug: Rendering Twice in StrictMode with useSyncExternalStore Official Example HOT 1
- Bug: script inside script render with SSR + renderToPipeableStream HOT 1
- Unexpected Renderer.js Behavior in Non-React Web Page HOT 1
- Natneam Mesele wants to pay 0 USD to have this issue fixed
- Bug: https://www.facebook.com/profile.php?id=100009820982674
- Bug: Incorrect 'removeChild' on 'Node' HOT 1
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.