Package Exports
- @rocket.chat/fuselage-hooks
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rocket.chat/fuselage-hooks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Welcome to @rocket.chat/fuselage-hooks 👋
React Hooks for Fuselage, Rocket.Chat's design system
🏠 Homepage
Install
yarn add @rocket.chat/fuselage-hooksRun tests
yarn testAPI Reference
Table of Contents
- useClassName
- useDebouncedUpdates
- useDebouncedReducer
- useDebouncedState
- useDebouncedCallback
- useExclusiveBooleanProps
- useMediaQuery
- useMergedRefs
- useToggle
useClassName
Hook to generate a BEM-compatible className value for a component.
Parameters
componentClassNamestring the style class which identifies the componentmodifiersObject the modifiers applied to the style class (optional, default{})classNames...string the additional style classes appended to theclassName
Returns string a BEM-compatible className in the format
(<block>|<block>__<element>) [...(<block>--<modifier>|<block>__<element>--<modifier>)] [...classNames]
useDebouncedUpdates
Hook to debounce the state updater function returned by hooks like useState() and useReducer().
Parameters
pair[any, function] the state and updater pair which will be debouncedpair.0any the state valuepair.1function the state updater function
delaynumber the number of milliseconds to delay the updater
Returns [any, function] a state value and debounced updater pair
useDebouncedReducer
Hook to create a reduced state with a debounced dispatch() function.
Parameters
reducerfunction the reducer functioninitializerArgany the initial state value or the argument passed to the initial state generator functioninitializerfunction the initial state generator functiondelaynumber the number of milliseconds to delay the updater
Returns [any, function] a state and debounced dispatch() function
useDebouncedState
Hook to create a state with a debounced setter function.
Parameters
initialValue(any | function) the initial state value or the initial state generator functiondelaynumber the number of milliseconds to delay the updater
Returns [any, function] a state and debounced setter function
useDebouncedCallback
Hook to memoize a debounced version of a callback.
Parameters
callbackfunction the callback to debouncedelaynumber the number of milliseconds to delaydeps(Array<any> | undefined) the hook dependencies
Returns function a memoized and debounced callback
useExclusiveBooleanProps
Hook for asserting mutually exclusive boolean props. Useful for components that use boolean props to choose styling variants.
Parameters
propsObject the mutually exclusive boolean propsThrows Error if two or more booleans props are set as true
useMediaQuery
Hook to listen to a media query.
Parameters
querystring? the CSS3 media query expression
Returns bool true if the media query matches; false is it does not match or the query is not defined
useMergedRefs
Hook to merge refs and callbacks refs into a single callback ref. Useful when your component need a internal ref while receiving a forwared ref.
Parameters
Returns function a merged callback ref
useToggle
Hook to create a toggleable boolean state.
Parameters
initialValue(any | function) the initial value or the initial state generator function
Returns [any, function] a state boolean value and a state toggler function
Author
👤 Rocket.Chat
- Twitter: @RocketChat
- Github: @RocketChat
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator