use-gravatar
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

npm version

useGravatar

A React hook (memoized) for getting gravatar's url based on email address

Usage

import { useGravatar } from 'use-gravatar';

const Component = ({ email } : { email: string }) => {
  const src = useGravatar(email, 48);
  return (
    <img src={src} alt="Avatar" />
  )
}

API

/**
 * Simple function to generate a gravatar avatar image url based on email and size
 * @param email {string} Email to use for Gravatar
 * @param [size] {number} Size of avatar (in pixels)
 */
export declare const toGravatar: (email: string, size?: number) => string;
/**
 * Hook to generate and memoize a gravatar avatar image url based on email and size
 * @param email {string} Email to use for Gravatar
 * @param [size] {number} Size of avatar (in pixels)
 */
export declare const useGravatar: (email: string, size?: number) => string;
/**
 * Hook to create and memoize (based on email) a gravatar avatar image url generation function based on size
 * This should be used when same email Gravatar is used in the same component in different sizes
 * @param email {string} Email to use for Gravatar
 */
export declare const useGravatarFactory: (email: string) => (size: number) => string;
/**
 * MD5 function, converts input to MD5 hex string
 * @param input {string} Input string
 */
export declare const md5hex: (input: string) => string;

LICENSE

MIT

Package Sidebar

Install

npm i use-gravatar

Weekly Downloads

26

Version

1.0.1

License

MIT

Unpacked Size

26.7 kB

Total Files

16

Last publish

Collaborators

  • elisherer