Coder Social home page Coder Social logo

Comments (5)

WebDevSimplified avatar WebDevSimplified commented on August 22, 2024

You can destructure this as { loading: otherLoadingName } and with an object you can get only the parts you need.

from useful-custom-react-hooks.

jkutianski avatar jkutianski commented on August 22, 2024

Yes, I know. Looks more common to return something more like useState()

from useful-custom-react-hooks.

WebDevSimplified avatar WebDevSimplified commented on August 22, 2024

I think it is really more personal preference which return method is most familiar. I generally prefer to work with objects unless I know I will be using all values returned from the function.

from useful-custom-react-hooks.

jkutianski avatar jkutianski commented on August 22, 2024

I agree with you about the return preference, and I generally prefer to return Objects. I explain how instead of why. Sorry, my fault.
The most common React hooks use arrays as returns. In this case, I think, it's more about destructuring preference and consistency between all the hooks.
It is much clearer in useTimeOut(). useAsync() is more like an edge case because it returns 3 values and if you want to use only 2 values you have to use a [value ,, loading] and it is a bit more error-prone.

hooks/blob/f5dda2e69d51e5da52aa75f21c6e83610def5923/src/2-useTimeout/useTimeout.js#L29
In this case, this looks much more similar to useState() to me.

const [ setTimeout ] = useTimeout()

I forgot to tell you that I personally really appreciate what you do. You help me so much with your videos.

from useful-custom-react-hooks.

WebDevSimplified avatar WebDevSimplified commented on August 22, 2024

I appreciate the explanation. I still plan to keep the hooks as they are so they match with what I showed in the video, but if you implement these hooks in your own project you are more then welcome to modify them to your needs.

from useful-custom-react-hooks.

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.