Skip to content

此页面的翻译正在准备中,暂时显示英文原文。

参考

Hooks

  • useAsyncEffectuseAsyncEffect is a React hook for handling asynchronous side effects in React components.
  • useAvoidKeyboarduseAvoidKeyboard is a React hook that helps fixed-bottom elements avoid the on-screen keyboard.
  • useBodyScrollLockuseBodyScrollLock is a React hook that locks body scroll while the component is mounted.
  • useBooleanStateuseBooleanState is a React hook that simplifies managing a boolean state.
  • useCallbackOncePerRenderuseCallbackOncePerRender is a React hook that ensures a callback function is executed only once, regardless of how many times it's called.
  • useConditionalEffectuseConditionalEffect is a React hook that conditionally executes effects based on a predicate function.
  • useControlledStateuseControlledState is a React hook that allows you to control both controlled and uncontrolled states.
  • useCounteruseCounter is a React hook that manages a numeric counter state with increment, decrement, and reset capabilities.
  • useDebounceuseDebounce is a React hook that returns a debounced version of the provided callback function.
  • useDebouncedCallbackuseDebouncedCallback is a React hook that returns a debounced version of the provided callback function.
  • useDebouncedValueuseDebouncedValue is a React hook that returns a debounced copy of the given value.
  • useDoubleClickuseDoubleClick is a React hook that differentiates between single and double click events.
  • useGeolocationuseGeolocation is a React hook that retrieves and tracks the user's geographical location.
  • useImpressionRefuseImpressionRef is a React hook that measures the time a specific DOM element is visible on the screen and executes callbacks when the element enters or exits the viewport.
  • useInputStateuseInputState is a React hook that manages an input state with optional value transformation.
  • useIntersectionObserveruseIntersectionObserver is a React hook that detects whether a specific DOM element is visible on the screen.
  • useIntervaluseInterval is a React hook that executes a function at a specified interval.
  • useIsClientuseIsClient is a React hook that returns true only in the client-side environment.
  • useIsomorphicLayoutEffectuseIsomorphicLayoutEffect is a React hook that provides the behavior of useLayoutEffect without triggering warnings during server-side rendering.
  • useKeyboardHeightuseKeyboardHeight is a React hook that tracks the on-screen keyboard height.
  • useList — A React hook that manages an array as state.
  • useLoadinguseLoading is a React hook that simplifies managing the loading state of a Promise.
  • useLongPressuseLongPress is a React hook that detects when an element is pressed and held for a specified duration.
  • useMap — A React hook that manages a key-value Map as state.
  • useNetworkStatususeNetworkStatus is a React hook that provides access to the Network Information API.
  • useOutsideClickEffectuseOutsideClickEffect is a React hook that triggers a callback when a click event occurs outside the specified container(s).
  • usePageVisibilityusePageVisibility is a React hook that detects page visibility changes.
  • usePreservedCallbackusePreservedCallback is a React hook that maintains a stable reference to a callback function while ensuring it always has access to the latest state or props.
  • usePreservedReferenceusePreservedReference is a React hook that helps maintain the reference of a value when it hasn't changed, while ensuring you can safely use the latest state.
  • usePrevioususePrevious is a React hook that returns the previous value of the input state.
  • useRefEffectuseRefEffect is a React hook that helps you set a reference to a specific DOM element and execute a callback whenever the element changes.
  • useSafeAreaInsetuseSafeAreaInset is a React hook that tracks safe area inset changes.
  • useScrollDirectionuseScrollDirection is a React hook that detects scroll direction.
  • useSet — A React hook that manages a Set as state.
  • useStorageStateuseStorageState is a React that functions like useState but persists the state value in browser storage.
  • useThrottleuseThrottle is a React hook that creates a throttled version of a callback function.
  • useThrottledCallbackuseThrottledCallback is a React hook that returns a throttled version of the provided callback function.
  • useThrottledValueuseThrottledValue is a React hook that returns a throttled copy of the given value.
  • useTimeoutuseTimeout is a React hook that executes a callback function after a specified delay.
  • useToggleuseToggle is a React hook that simplifies managing a boolean state.
  • useVisibilityEventuseVisibilityEvent is a React hook that listens to changes in the document's visibility state and triggers a callback.
  • useVisualViewportuseVisualViewport is a React hook that tracks Visual Viewport changes.

组件

  • ImpressionAreaImpressionArea is a component that measures the time a specific DOM element is visible on the screen and executes callbacks when the element enters or exits the viewport.
  • SeparatedSeparated is a component that inserts a specified component between each child element.
  • SwitchCaseSwitchCase is a component that allows you to declaratively render components based on a given value, similar to a switch-case statement.

工具函数

  • buildContextbuildContext is a helper function that reduces repetitive code when defining React Context.
  • disableBodyScrollLockdisableBodyScrollLock is a utility function that unlocks the body scroll.
  • enableBodyScrollLockenableBodyScrollLock is a utility function that locks the body scroll.
  • getKeyboardHeightgetKeyboardHeight is a utility function that returns the current on-screen keyboard height in pixels.
  • getSafeAreaInsetgetSafeAreaInset is a utility function that returns all safe area insets in pixels as an object.
  • isAndroidisAndroid is a utility function that detects whether the current device is running Android.
  • isIOSisIOS is a utility function that detects whether the current device is running iOS or iPadOS.
  • isKeyboardVisibleisKeyboardVisible is a utility function that checks whether the on-screen keyboard is currently visible.
  • isServerisServer is a utility function that checks if the code is running on the server.
  • mergePropsmergeProps is a utility function that merges multiple props objects into a single object.
  • mergeRefs — This function takes multiple refs (RefObject or RefCallback) and returns a single ref that updates all provided refs.
  • subscribeKeyboardHeightsubscribeKeyboardHeight is a utility function that subscribes to changes in the on-screen keyboard height.

基于 MIT 许可证发布。