Hello Hook👏
hook
Jedi Hongbin
hongbin.xyz meta.hongbin.xyz kmyc.hongbin.xyz
展开
-
useIntervale
再次感受react hook的魅力取自dan的博客使用 React Hooks 使 setInterval 声明式function useInterval(callback, delay) { const savedCallback = useRef(); // Remember the latest callback. useEffect(() => { savedCallback.current = callback; }, [callback]); // Se原创 2022-05-21 10:36:48 · 104 阅读 · 0 评论 -
useLocalStorage
import { useState } from "react";const useLocalStorage = (key = "", initialValue = "") => { const [state, setState] = useState(() => { try { const item = window.localStorage.getItem(key); return item ? JSON.parse(item) : initialVa原创 2021-02-23 11:20:36 · 2490 阅读 · 0 评论 -
useEventListener
import { EventType } from "@testing-library/react";import { useEffect, useRef } from "react";type TUseEventListener = ( target: any | HTMLElement, eventType: EventType, listener: EventListener, options?: EventListenerOptions) => void;const原创 2021-02-23 11:18:29 · 1182 阅读 · 0 评论 -
useUser
import { useState, useCallback } from "react";export enum USER { name = "name", password = "password",}interface IUser { [USER.name]: string; [USER.password]: string;}type HandleChangeUser = (e: React.ChangeEvent<HTMLInputElement>) =&原创 2021-02-23 11:03:08 · 216 阅读 · 0 评论 -
useTimeout
import React from "react";const useTimeout = (callback: () => void, delay: null | number): void => { const savedCallback = React.useRef<any>(); React.useEffect(() => { savedCallback.current = callback; }, [callback]); React.u原创 2021-02-23 11:00:32 · 609 阅读 · 0 评论 -
useFullScreenAdaptive
import { useState, useEffect, useMemo, useCallback } from "react";type TUseFullScreenAdaptive = [ isFullScreen: boolean, fullscreenName: string, exitFullscreenName: string];const useFullScreenAdaptive = ( callback?: () => void): TUseFullSc原创 2021-02-23 10:59:02 · 291 阅读 · 0 评论 -
useHttp
import { useEffect, useState } from "react";import http, { HttpMethod, HttpResponse, HttpError, HttpRequestConfig,} from "../server/httpService";interface IProps { url: string; method?: HttpMethod; options?: HttpRequestConfig;}interfac原创 2021-02-23 10:54:14 · 458 阅读 · 0 评论 -
useFetch
import { useEffect, useState } from "react";const useFetch = (url = "", options = undefined) => { const [data, setData] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); useEffect(() =&原创 2021-02-23 10:51:08 · 1799 阅读 · 0 评论