react-blurhash provides React components for efficiently displaying Blurhash placeholders in web applications. Blurhash is a compact algorithm for representing a blurred version of an image, enabling a smooth user experience by showing a low-resolution placeholder while the full image loads. Currently at version 0.3.0, the package offers two core components: `<Blurhash />` for a higher-level, self-scaling implementation, and `<BlurhashCanvas />` for direct canvas rendering, offering granular control over the decoding and display process. The library ships with TypeScript types, enhancing developer experience and type safety. It's built upon the core `blurhash` algorithm and requires `react` (>=15) and `blurhash` (^2.0.3) as peer dependencies, which must be installed separately. The package is actively maintained, though its pre-1.0 version number suggests the API might evolve in future major releases.
npm install react-blurhashVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to render a Blurhash placeholder using the `<Blurhash />` component. It illustrates basic usage with an example hash string and common props like width, height, and resolution. Remember to install `blurhash` and `react`.
Always check the release notes and changelog when upgrading, even for minor versions, and thoroughly test your application.
Ensure both `react-blurhash` and `blurhash` are installed: `npm install --save blurhash react-blurhash` or `yarn add blurhash react-blurhash`.
Optimize `resolutionX` and `resolutionY` to the lowest acceptable values (e.g., 32-64px) for your design to balance visual quality and performance. The default is 32.
If dynamic sizing is required, use React refs and the `ResizeObserver` API (or a library like `react-resize-detector`) to measure the parent container's dimensions and pass numerical `width` and `height` values to the Blurhash components.
Install the `blurhash` package: `npm install blurhash` or `yarn add blurhash`.
Ensure your target browser supports `Uint8ClampedArray` (most modern browsers do, >=IE11). For server-side rendering (SSR) in Node.js, you might need to use a canvas polyfill to provide this global object.
Ensure the `hash` prop is a valid, non-empty Blurhash string. Validate the source of your Blurhash strings (e.g., from an API or encoding process).