# extendify/3.0.5/src/Draft/hooks/useUnsplashImages.js

Extendify, version 3.0.5. 18 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.0.5/code/src/Draft/hooks/useUnsplashImages.js
- Raw: https://pluginprobe.com/plugins/extendify/3.0.5/raw/src/Draft/hooks/useUnsplashImages.js
- Modified: 2025-05-19T12:47:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/3.0.5/code/src/Draft/hooks/useUnsplashImages.js#L10-L20`.

```javascript
import { fetchImages } from '@shared/lib/unsplash';
import { useUnsplashCacheStore } from '@shared/state/unsplash-cache';
import useSWRImmutable from 'swr/immutable';

const searchImages = async (search, source = null) => {
	const cache = useUnsplashCacheStore.getState();
	if (search === 'unsplash' && !cache.isEmpty() && !cache.hasExpired()) {
		return cache.images;
	}
	return await fetchImages(search, source);
};

export const useUnsplashImages = (search, source = null) => {
	const key = search || 'unsplash';
	const { data, error } = useSWRImmutable(key, () => searchImages(key, source));
	return { data, error, loading: !data && !error };
};

```
