Coder Social home page Coder Social logo

Comments (2)

antonioru avatar antonioru commented on June 10, 2024

this is a very good utility and definitely a good idea, but should it be a hook really? if so why not just a common utility?

I mean... we can definitely provide a utility checking if it is server side or client side rendering and we can possibly export it from the library, something like this:

const isServerSideRendering = () => typeof window !== 'undefined'; 

// import something like this maybe?

import { isServerSideRendering } from 'beautiful-react-hooks/commons'; 

or we can improve and extend (and rename) the already existing isClient function.

I generally tend to consider hooks pieces of React-related business logics that help the devs to use (or hook into) React features, but this is just a check that's not strictly related to any React feature...
to be fair such a utility can be used in many other context...

I know a lot of other React hook libraries have such a hook, but in fact one of the reason I wrote this library is to enforce good practices using React hooks (which are very often overlooked) and I completely disagree with this approach for the instance:

https://usehooks-ts.com/react-hook/use-ssr

this is actually the reason why I avoided having hooks like useArray or useMap, these are basic javascript structure that are not related to React and - in my opinion - tend to pollute the codebases. (( looks like over engineering to me ))

Please let me know what you think

from beautiful-react-hooks.

playerony avatar playerony commented on June 10, 2024

I've made some small research about that and I came to the conclusion that It's quite tricky :P I've found this in docs (https://reactjs.org/docs/hooks-custom.html#extracting-a-custom-hook): A custom Hook is a JavaScript function whose name starts with ”use” and that may call other Hooks. So may use other hooks, but doesn't have to. The only difference between the function and the hook, in this case, is that this automatically forces it to use rules of hooks. From the same doc above: [...] it’s just like a normal function. Its name should always start with use so that you can tell at a glance that the rules of Hooks apply to it.. But I also understand your perspective and I think it does not make sense as far as isCliect function is more appropriate and reusable. To close! Thanks for this brainstorm! It's always good to learn something new: P

from beautiful-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.