Git Product home page Git Product logo

react-hooks's Introduction

React Hooks

This is a collection of frequently used react hooks to support development within baidu, contributions from community are also welcomed.

Project structure

This is a typical yarn workspace based monorepo, each hook creates a package in packages folder, the folder name is dash-cased and without the use prefix.

Package name must comform a format of @huse/foo-bar.

Each package should named export at least one hook like:

import {useInputValue} from '@huse/input-value';

Unit tests are recommended, they are placed inside src/__tests__ folder with an extension of .test.js, we highly recommend a 100% of branch coverage.

Document

By now we are unable to publish document online since docz build fails, you can find description to package in its README.md, or to start a document site locally.

yarn
yarn doc:dev

Open http://localhost:3000 to view documents about hooks.

All hooks

Hook Description
useActionPending Add a pending indicator to any ascyn function
useBoolean Methods to control a boolean state
useSwitch More convenient way to use boolean state
useToggle Simply toggle boolean state
useClickOutside Trigger callback when clicks outside a specific element
useArray Methods to control array state
useSet Methods to control Set state
useMap Methods to control Map state
useDebouncedEffect Debounce an effect on value change
useDebouncedValue Debounce a value change
useDebouncedCallback Debounce a callback function
useRenderTimes Return times of component rendered
useChangeTimes Return times of a value changed
useUpdateCause Observe the cause of component update
useDerivedState Derive a state from external prop
useDocumentEvent Add listeners to document's event
useDocumentTitle Change document.title
useEffectRef More reliable function based ref with clean-up ability
useElementResize Trigger callback when element resize
useElementSize Return element's size
useHover Observe mouse enter and leave to element
useImmerReducer A useReducer with immer support
useImmerState A useState with immer support
useInfiniteScroll Encapsulate methods and props to implement infinite scroll
useInputValue Bound a value and it's change handler to input element
useOnScreenCallback Trigger callback when element intersects with viewport
useOnScreen Return whether element intesects with viewport
useOnScreenLazyValue Lazy initialize a value when it intersects with viewport
useLocalStorage Visit and update local storage
useMedia Return whether a media query is currently matched
usePreferDarkMode Return whether user prefers dark color scheme
useMergedRef Merge multiple ref into a single one
useMethodsNative Wrap methods around a state
useMethodsExtensionNative Wrap methods around a setState function
useMethods useMethodsNative with immer support
useMethodsExtension useMethodsNative with immer support
useOnLine Return user is current online of offline
useCounter Methods to control a number state with increment and decrement
usePerformanceTiming Collect performance data and send to callback
useLayoutTiming Collect timings of a component's layout
usePoll Periodically trigger an async function and manage its response
usePreviousValue Get previous version of a value
usePreviousEquals Return whether a value is equals to that on previous render
useOriginalCopy Track back a value to get a reference equals copy when content are identical
useOriginalDeepCopy useOriginalCopy with deep equal support
useRequestCallback Return a function to trigger request with its data, error and pending state
useRequest Trigger request on params change and return its data, error and pending state
useScript Load an external script
useScriptSuspense Load an external script with suspense
useScrollIntoView Scroll an element into viewport
useScrollLock Lock scroll of document
useScrollPosition Get current scroll top and left
useScrollTop Get current scroll top
useScrollLeft Get current scroll left
useSelection Manage state to work with list selection, including multiple and range selection
useSnapshotState Get a state with undo and redo support
useTimeout Trigger callback after specified time
useInterval Trigger callback periodically
useStableInterval useInterval but counts ellapsed time of function execution, both sync and async
useTransitionState A state which will revert back to its initial value when updated
useForceUpdate Force update a component
useWindowSize Get the size of window

react-hooks's People

Contributors

bdwenxi avatar ice-zjchen avatar otakustay avatar tonyjeffrey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.