Hi Guys, could anyone can share some bast custom hooks ?
thanks.
For further actions, you may consider blocking this person and/or reporting abuse
Hi Guys, could anyone can share some bast custom hooks ?
thanks.
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (2)
You can find some pretty good hooks here.
github.com/hassanzohdy/react-hooks
Here are some examples of what you will find there.
useFetcher
This is a powerful fetcher hook that will help you to fetch data from the server and handle the loading state and errors but with more configurations.
You can also know which is the current page you're on by using
currentPageproperty.Another cool feature is
paginatableproperty which tells you whether you should display the pagination buttons or not.You might also use
isLastPageto know if you're on the last page or not so you can disable theload morebutton.Here are the entire properties you can use:
Also you can set fetching options by passing it as the second argument to the
useFetcherhook.Or you can set the default params by using
setFetchOptionsmethod.Here is the entire available options
You can see the entire documentation of usage in our article in Dev.to
useInputValue
useInputValue<T>(defaultValue: T): [T: ((newValue): any => void)]This hook can be very useful when working with form inputs so it will give you an easier state changer callback to update the input value automatically.
The normal way is:
With
useInputValueIt can take the value from various types,as the
onChangesends an evente, theuseInputValuevalueDetector will try to get the value from any of the followinge.target.valuee.valuee.ide.texteIf no value for
eit will be set as empty string.useOnce
useOnce(callback: () => (void | Destructor))Works exactly the same as
useEffect(() => {}, [])but this one will relive you from adding the second argument and will skip the eslint checker for any missing dependencies that will not reflect on the side effect.useForceUpdate
useForceUpdate(): () => voidA very useful hook when you want to re-render the component without using the
useStatehook.useOuterClick
This hook will allow you to detect when the user clicks outside an element.
The
erepresents the click event and the element represent the value of thedivRef's current element.useStateDetector
useStateDetector(propValue: any): [propValue: any, valueUpdater: (newValue: any) => void]This hook works exactly the same as
useStateexcept it will be updated if the given value is updated.This one is very useful if you're relying on a value passed from the parent component and needs to detect if it has been changed.
After the first click on the button the value will remain false, now let's try
useStateDetectorIn this case it will always get updated whenever the passed
disabledprop in theChildComponentis updated.thank you for your advice .