Skip to content

Repository files navigation

@build-from-bits/react-helpers

React hooks and helpers: script loading, previous-value tracking, and color/URL utilities.

Install

npm install @build-from-bits/react-helpers

Hooks

  • usePrevious(value) — returns the previous value across renders.
  • useExternalScripts({ url }) — loads an external script into <head> while mounted.
  • usePaymentGatewayScript() — loads the Razorpay checkout script.

Helpers

  • goBack()window.history.back() (no-op on the server).
  • isNativePlatform()true when running inside a Capacitor native shell (reads the runtime window.Capacitor global).
  • hexToRGB(cssVar) / rgbToHex(rgb) — color conversion helpers.
  • getExtension(path) — lowercased file extension.
  • capitalizeFirstLetter(str).
  • getWhatsAppURL(phone, message) — WhatsApp deep link.
  • COUNTRY_CODE, WHATSAPP — constants.

Usage

import { usePrevious, useExternalScripts, getWhatsAppURL } from '@build-from-bits/react-helpers';

function Component() {
  const prev = usePrevious(count);
  useExternalScripts({ url: 'https://cdn.example.com/x.js' });
  return <a href={getWhatsAppURL('9876543210', 'Hi')}>Chat</a>;
}

Publish

npm run build
npm run pack:check
npm run publish:npm
npm run publish:github

License

Licensed under the Apache License 2.0.

Copyright 2026 Build From Bits Pvt Ltd.

About

React hooks and helpers: script loading, previous-value tracking, and color/URL utilities.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages