This file contains hidden or 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
| # bash | |
| eval $(/opt/homebrew/bin/brew shellenv) | |
| alias bashrefresh=". ~/.bash_profile" | |
| alias bashopen="open ~/.bash_profile" | |
| # fnm | |
| eval "$(fnm env)" | |
| # mac | |
| alias big-sur="xcode-select --install" |
This file contains hidden or 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
| class SetInterval extends React.Component { | |
| componentDidMount() { | |
| this.setNewInterval(); | |
| } | |
| componentDidUpdate(prevProps) { | |
| if (this.props.delay !== prevProps.delay) { | |
| clearInterval(this.interval); | |
| this.setNewInterval(); | |
| } |
This file contains hidden or 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 { useCallback, useState } from "react"; | |
| export default function useMutation(mutate) { | |
| const [isLoading, setIsLoading] = useState(false); | |
| const [data, setData] = useState(null); | |
| const [error, setError] = useState(null); | |
| const runMutation = useCallback( | |
| (...args) => { | |
| setIsLoading(true); |
This file contains hidden or 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 useInputValue = initialValue => { | |
| const [value, setX] = React.useState(initialValue); | |
| const prop = p => o => o[p]; | |
| const setValue = Ramda.compose( | |
| setX, | |
| prop("value"), | |
| prop("target"), | |
| ); |
This file contains hidden or 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
| password: Yup.string() | |
| .required("Password is required") | |
| .min(8, "Password must be at least 8 characters long") | |
| .matches(/\d/, "Password must contain a number") | |
| .matches( | |
| /[\W_]/, | |
| "Password must contain a non-alphanumberic character", | |
| ), | |
| // new RegExp(`^((?!${name}).)*$`); |
This file contains hidden or 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 composeDecorators = (first, ...decorators) => | |
| decorators.reduce( | |
| (accumulatedDecorators, nextDecorator) => storyFn => | |
| accumulatedDecorators(() => nextDecorator(storyFn)), | |
| first, | |
| ); | |
| // please don't | |
| const ds = (i, ...r) => r.reduce((a, d) => f => a(() => d(f)), i); |
This file contains hidden or 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
| function useStorageListener(key, onChange) { | |
| useEffect(() => { | |
| function handleChange({ key: eventKey, newValue }) { | |
| if (eventKey === key) { | |
| const parsed = newValue && JSON.parse(newValue); | |
| onChange(parsed); | |
| } | |
| if (!eventKey) { | |
| onChange(getLocalStorageItem(key)); | |
| } |
This file contains hidden or 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 [hasCheckedSession, setHasCheckedSession] = useState(false); | |
| useEffect(() => { | |
| if (hasCheckedSession) { | |
| return; | |
| } | |
| if (!sessionToken) { | |
| setHasCheckedSession(true); | |
| return; |
This file contains hidden or 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 withFormikField = F => { | |
| const HoC = ({ name, onBlur, onChange, ...rest }) => { | |
| const handleChange = value => onChange({ target: { name, value } }); | |
| const handleBlur = () => onBlur({ target: { name } }); | |
| return <F {...rest} onChange={handleChange} onBlur={handleBlur} />; | |
| }; | |
| return HoC; | |
| }; | |
| const SelectForFormik = withFormikField(Select); |
This file contains hidden or 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
| function useTimeout() { | |
| const ids = React.useRef([]); | |
| React.useEffect(() => () => ids.current.forEach(clearTimeout), []); | |
| // setTimeout takes a callback and a delay, then returns the id associated with the timeout. | |
| const _setTimeout = React.useCallback((callback, delay) => { | |
| const id = setTimeout(callback, delay); | |
| ids.current.push(id); |