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 MainApi extends HttpClient { | |
| private static classInstance?: MainApi; | |
| private constructor() { | |
| super('https://api.awesome-site.com'); | |
| } | |
| public static getInstance() { | |
| if (!this.classInstance) { | |
| this.classInstance = new MainApi(); |
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 MainApi extends HttpClient { | |
| private static classInstance?: MainApi; | |
| private constructor() { | |
| super('https://api.awesome-site.com'); | |
| } | |
| ... | |
| } |
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 MainApi extends HttpClient { | |
| private constructor() { | |
| super('https://api.awesome-site.com'); | |
| } | |
| ... | |
| } |
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 { useState } from 'react'; | |
| interface Status { | |
| pending: boolean; | |
| resolve: boolean; | |
| reject: boolean; | |
| } | |
| interface ReturnStatus<T> extends Status { | |
| data: T | null; |
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 { useEffect } from 'react'; | |
| export default () => { | |
| useEffect(() => { | |
| const initialOverflow = window.getComputedStyle(document.body).overflow; | |
| document.body.style.overflow = 'hidden'; | |
| return () => { | |
| document.body.style.overflow = initialOverflow; |
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 { useEffect } from 'react'; | |
| type PassedElement = Element | Window; | |
| type UseEventListener = (h: EventListener, e: string, el?: PassedElement) => void; | |
| const useEventListener: UseEventListener = (handler, event, element = window) => { | |
| useEffect(() => { | |
| const isSupported = element && element.addEventListener; |
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 { useState } from 'react'; | |
| type HandleToggle = (value: boolean | React.MouseEvent) => void; | |
| export default (defaultValue = false): [boolean, HandleToggle] => { | |
| const [isOn, toggle] = useState<boolean>(defaultValue); | |
| const handleToggle: HandleToggle = (value) => { | |
| const toggleState = typeof value === 'boolean' ? value : !isOn; |
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 { useState } from 'react'; | |
| export type ChangeEvent = React.ChangeEvent<HTMLInputElement>; | |
| export type OnChange = (event: ChangeEvent | string) => void; | |
| export default (defaultValue = ''): [string, OnChange] => { | |
| const [value, setValue] = useState<string>(defaultValue); | |
| const onChange: OnChange = (data) => { | |
| const value = typeof data === 'string' ? data : data.target.value; |
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 { AxiosRequestConfig } from 'axios'; | |
| import { CreateUserBody } from './types'; | |
| class MainApiProtected extends HttpClient { | |
| public constructor() { | |
| super('https://api.awesome-site.com'); | |
| this._initializeRequestInterceptor(); | |
| } |
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 HttpClient from './http-client'; | |
| import { User } from './types'; | |
| class MainApi extends HttpClient { | |
| public constructor() { | |
| super('https://api.awesome-site.com'); | |
| } | |
| public getUsers = () => this.instance.get<User[]>('/users'); | |