I'm a professional Full stack Software Engineer who specifically is interested building projects' low-level structure.
I'm looking for a good oportunity for hiring, mail me if you find me fit.
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.
import{useFetcher}from'@mongez/react-hooks';import{getProductsList}from'./api';exportdefaultfunctionProductsList(){const{records,isLoading,error,loadMore,goToPage}=useFetcher(params=>getProductList(params));if(isLoading){return<div>Loading...</div>;}if(error){return<div>{error}</div>;}return(<>{records.map(product=>(<divkey={product.id}>{product.name}</div>))}<buttononClick={loadMore}>Load More</button><buttononClick={()=>goToPage(2)}>Go To Page 2</button></>);}
You can also know which is the current page you're on by using currentPage property.
Another cool feature is paginatable property which tells you whether you should display the pagination buttons or not.
You might also use isLastPage to know if you're on the last page or not so you can disable the load more button.
Here are the entire properties you can use:
typeFetcherOutput={records:any[];// the fetched recordserror:null|any;// the error if anyload:(params?:Record<string,any>)=>Promise<any>;// load the datareload:(params?:Record<string,any>)=>Promise<any>;// reload the same dataisLoading:boolean;// whether the data is loading or notloadMore:(params?:Record<string,any>)=>Promise<any>;// load more datagoToPage:(page:number)=>Promise<any>;// go to a specific pagereset:()=>Promise<any>;// load the default params isFirstPage:boolean;// whether you're on the first page or notisLastPage:boolean;// whether you're on the last page or notcurrentPage:number;// the current page you're onresponse?:AxiosResponse;// the response objecttotalPages:number;// the total pagestotalRecords:number;// the total recordscurrentRecords:number;// the current recordsdefaultParams:Record<string,any>;// the default params that will be passed to the fetcher method on each request beside the current paramsparams:Record<string,any>;// the current paramspaginatable:boolean;// whether the data is paginatable or not}
Also you can set fetching options by passing it as the second argument to the useFetcher hook.
typeFetcherOptions={defaultParams?:Record<string,any>;// the default params that will be passed to the fetcher method on each request beside the current params// the keys that will be taken from the `response.data` object and will be used as the output// it supports dot notation like `paginationInfo.currentPage` or `meta.totalRecords`keys?:{records?:string;itemsPerPage?:string;currentPage?:string;totalPages?:string;totalRecords?:string;currentRecords?:string;pageNumber?:string;};};
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.
It can take the value from various types,as the onChange sends an event e, the useInputValue valueDetector will try to get the value from any of the following
e.target.value
e.value
e.id
e.text
e
If no value for e it 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.
Please note that this hook will ignore any updates that occurs to any states/variables inside it as it will be executed only once after the first render.
useForceUpdate
useForceUpdate(): () => void
A very useful hook when you want to re-render the component without using the useState hook.
import{useForceUpdate}from"@mongez/react-hooks";exportfunctionHelloWorld(){constforceUpdate=useForceUpdate();useEffect(()=>{// just dummy example for demonstrationdocument.addEventListener("scroll",()=>{forceUpdate();});},[]);// this value will be updated each time the user scrolls up or downconstscrollTop=window.pageYOffset;return(<><div>Scroll Top Position Is: ${scrollTop}</div></>);}
useOuterClick
This hook will allow you to detect when the user clicks outside an element.
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 .