GithubHelp home page GithubHelp logo

Comments (5)

markerikson avatar markerikson commented on April 19, 2024 2

@nbrignol Why are you trying to write a hook as a class? There's no reason to.

from react.

yanup2913 avatar yanup2913 commented on April 19, 2024

@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 avatar nbrignol commented on April 19, 2024

@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.

markerikson avatar markerikson commented on April 19, 2024

@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 avatar nbrignol commented on April 19, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.