react-useunsplash
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-3 • Public • Published

useUnsplash - React hook

React hook to get a unsplash image and its metadata with ease.

Usage

yarn add @zeekrey/useunsplash
npm install @zeekrey/useunsplash

Basic usage:

const [image, imageMeta] = useUnsplash({
                apikey: '21jkwopdio29khp192',
                id: 'VMPhyAoVqqk',
                options: { w: 600, ar: '2:1', fit: 'crop' },
            }),

Details

This is the object thats needs to be provided when using the hook:

The hook returns an array with the following two parameters:

interface Props {
    apikey: string
    id: string
    options?: {
        w?: number
        h?: number
        ar?: string
        crop?: string
        fm?: string
        q?: number
        fit?: string
        dpr?: number
    }
}

function useUnsplash(
    { apikey, id, options = {} }: Props = { apikey: '', id: '' },
): [string | undefined, UnsplashObject | undefined] {
    //...
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Development

Run tests with

yarn test

To run tests you need to create env file like this:

cd <project-root> && echo process.env.APIKEY = 'your_api_key' > .env.js

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i react-useunsplash

Weekly Downloads

0

Version

0.0.1-3

License

MIT

Unpacked Size

6.82 kB

Total Files

6

Last publish

Collaborators

  • zeekrey