Skip to content

turtleflyer/smart-hooks

Repository files navigation

smart-hooks

Collection of React hooks that supplements a set of standard hooks of React library extending their logic.

  • useInterstate

    useInterstate is a simple, lightweight, and powerful global state management solution for React projects designed to stick as close as possible to a natural usage pattern found in the standard hook useState. It is minimalistic and does not require too much to start using. No special boilerplates. No big learning curve. The hook useInterstate is just working familiarly out-of-box. Also, it should work in the upcoming concurrent mode as we can judge assuming from information that is available now and based on our tries with the experimental build of React.

    The library is written in TypeScript and nicely typed. The test coverage is solid and embraces various complex use cases. More than that, its name sounds cool.

  • useMultiState provides a way to wrap multiple useState's into one hook that will act exactly way but without to be verbose and messy.

  • useSmartRef attaches a callback to the event when the element is creating inside the component. This callback returns a clean-up function having a chance to fire up when the component gets rid of the element, or the entire component loses its existence.

  • There is a temptation to use the standard React hook useMemo not only for the sake of performance optimization. But in the official documentation, it says clearly: You may rely on useMemo as a performance optimization, not as a semantic guarantee. useSmartMemo is for the control over the execution of some part of code skipping it if values passed to a dependencies list do not change.