qwe
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
export default function Seo({title, description, image, type, structuredData}) { | |
const {asPath} = useRouter() | |
const titleTemplate = `${title} | Staiy` | |
return ( | |
<Head> | |
{/* <!-- Primary Meta Tags --> */} | |
<title>titleTemplate</title> | |
<meta name="title" content={titleTemplate} /> |
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, useReducer, useEffect} from 'react' | |
import axios from 'axios' | |
import {toastAlert, getError} from '@helpers' | |
const dataFetchReducer = (state, action) => { | |
switch (action.type) { | |
case 'FETCH_INIT': | |
return { | |
...state, | |
isLoading: true, |
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 {useReducer, useCallback} from 'react' | |
import useIsMounted from './useIsMounted' | |
function useStatus() { | |
const isMounted = useIsMounted() | |
const [{status, error}, setState] = useReducer((s, a) => ({...s, ...a}), { | |
status: 'rest', | |
error: null, | |
}) |
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' | |
// lock body scroll when modals are open 🔥 | |
// if isLocked isn't specified it will lock the page when mounted | |
function useLockBodyScroll(isLocked = true) { | |
useEffect(() => { | |
const originalStyle = window.getComputedStyle(document.body).overflow | |
if (isLocked) { | |
document.body.style.overflow = 'hidden' | |
} |
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} from 'react' | |
function useLocalStorage(key, initialValue) { | |
const [storedValue, setStoredValue] = useState(() => { | |
try { | |
const item = window.localStorage.getItem(key) | |
return item ? JSON.parse(item) : initialValue | |
} catch (error) { | |
return initialValue | |
} |
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 {useReducer, useCallback} from 'react' | |
import produce from 'immer' | |
const useImmerReducer = (reducer, initialState) => { | |
const cachedReducer = useCallback(produce(reducer), [reducer]) | |
return useReducer(cachedReducer, initialState) | |
} | |
export default useImmerReducer |
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' | |
let _id = 0 | |
const genId = () => ++_id | |
export default function useId() { | |
const [id, setId] = useState(null) | |
useEffect(() => setId(genId()), []) | |
return id | |
} |
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' | |
export default function useDebounce(value) { | |
const [debouncedValue, setDebouncedValue] = useState(value) | |
useEffect(() => { | |
const handler = setTimeout(() => { | |
setDebouncedValue(value) | |
}, 500) | |
return () => { |
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 Router, * as router from 'next/router' | |
const mockedRouter = { | |
push: path => { | |
action('navigated to')(path) | |
return new Promise((reject, resolve) => resolve()) | |
}, | |
replace: path => { | |
action('replaced url to')(path) | |
return new Promise((reject, resolve) => resolve()) | |
}, |
OlderNewer