This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react'; | |
/** | |
* Custom React Hook useWindowSize | |
* @returns width: {Number}, height: {Number} | |
*/ | |
export function useWindowSize() { | |
const isClient = typeof window === 'object'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRef, useEffect } from 'react'; | |
/** | |
* Custom React Hook usePrevious | |
* @returns ref.current {current: "ANY"} | |
* @default undefined | |
* @description It store the previous state when state changes. | |
* @example const previousState = usePrevios(state) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
const useClickOutside = ( | |
ref: React.MutableRefObject<HTMLElement>, | |
handler: (event: MouseEvent | TouchEvent) => void) => { | |
useEffect(()=>{ | |
const listener = (event: MouseEvent | TouchEvent) => { | |
if(!ref.current || ref.current.contains(event.target as Node)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inBrowser = typeof window !== 'undefined'; | |
// CHECK USER AGENT | |
const UA = inBrowser && window.navigator.userAgent.toLowerCase(); | |
const isIE = UA && /msie|trident/.test(UA); | |
const isIE9 = UA && UA.indexOf('msie 9.0') > 0; | |
const isEdge = UA && UA.indexOf('edge/') > 0; | |
const isAndroid = UA && UA.indexOf('android') > 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createContext, useContext } from 'react'; | |
import PropTypes from 'prop-types'; | |
const ExampleContext = createContext(); | |
function ExampleProvider({ children }) { | |
return ( | |
<ExampleContext.Provider value={}> | |
{children} |