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, useState } from 'react' | |
type User = { | |
firstName: string | |
lastName: string | |
email: string | |
} | |
type Updater = (user: User) => void |
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, useState } from 'react'; | |
type Props = { | |
children: React.ReactNode | React.ReactNode[]; | |
}; | |
type Context = { | |
isExpanded: boolean; | |
toggleItem?: () => void; | |
}; |
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' | |
/** | |
* Saves previous value, if you need to compare it to a current value | |
* @param value - anything you need to store as a previous value | |
*/ | |
export const usePrevious = <T>(value: T) => { | |
const ref = useRef<T>() | |
// Store current value in ref |