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

Extendify, version 3.1.6. 26 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.1.6/code/src/Draft/hooks/useUnsplashImages.js
- Raw: https://pluginprobe.com/plugins/extendify/3.1.6/raw/src/Draft/hooks/useUnsplashImages.js
- Modified: 2026-08-12T16:23:58+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.1.6/code/src/Draft/hooks/useUnsplashImages.js#L10-L20`.

```javascript
import {
	DEFAULT_IMAGE_SEARCH,
	resolveImageSearch,
} from '@shared/lib/image-search-defaults';
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 === DEFAULT_IMAGE_SEARCH &&
		!cache.isEmpty() &&
		!cache.hasExpired()
	) {
		return cache.images;
	}
	return await fetchImages(resolveImageSearch(search), source);
};

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

```
