Comments (2)
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.
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)
- The automated release is failing π¨ HOT 2
- useGlobalEvent should check `isClient` before referencing `window` HOT 1
- Can't resolve 'react-router-dom' HOT 7
- Typing for `useTimeout` is incorrect HOT 1
- Autogenerate CHANGELOG.md
- remove index.ts from the codebase to force correct imports HOT 4
- useThrottledCallback doesn't consider dependencies
- Update `react-router-dom` to v6 HOT 3
- I need help about writing tests, element.scrollWidth always is 0 HOT 3
- useAudio hook can't change src when input new src HOT 2
- useLocalStorage causing infinite loops when setValue is a dependency in a useEffect HOT 2
- Remove or reduce unsupported API console warnings HOT 3
- More feature from thrid libs HOT 2
- Type declaration error with useInterval hook's clearInterval function HOT 10
- Deprecate all react-router-dom related hooks HOT 1
- `useGeolocation` not updating state in Firefox desktop
- useAudioControls returning new controls object everytime state is updated
- :memo useWillUnmount should called useUnmount HOT 2
- Type resolution for ESM modules is broken HOT 6
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 beautiful-react-hooks.