The useImage hook gives you the ability to call an image from your Cloudinary account and apply transformations. The result is a URL generated by the SDK.
import{ useImage }from'use-cloudinary';
// Basic Image component
functionImage({ publicId, transformations, width, height, alt }){
Your Cloudinary cloud name, used to identify where we're getting our media from
Return values
Key
Type
Description
generateUrl
Func
An async function that accepts options and returns the URL of your Cloudinary asset
blurredPlaceholderUrl
Func
This function delivers your media in a low quality blur format, perfect for fallback placeholders while lazy-loading / initial load
url
undefined || String
When `generateUrl` is successful, url will return a URL string. More about React Query's return values here
isLoading
Boolean
isLoading state returns a boolean if the query is in a "hard" loading state. This means no cached data and the query is currently fetching.here
isErrro
Boolean
isError returns a boolean (true) if the query attempt resulted in an error (otherwise false). More about React Query return vairables here
isSuccess
Boolean
isSuccess returns a boolean (true) if the query attempt resulted in an error (otherwise false).More about React Query return vairables here
isIdle
Boolean
isIdle returns a boolean (true) if the query is initialized with enabled: false and no initial data is available (otherwise false). More about React Query return vairables here
inView
Boolean
The inView boolean changes dependent on the elements 'ref' coming into the viewport.
ref
Obj
A ref is used to return a reference to the element, directly supports "inView"
supportsLazyLoading
Boolean
Returns a boolean dependent on if the browser supports lazy-loading or not
error
Object
On failure, React Query returns an error object, surfacing the error message for use in the UI. More about React Query's return values here
generateUrl()
The generateUrl function is just a setState, used to fire off our internal query and pass our options into our SDK to generate our URL.
Key
Type
Required
Description
publicId
String
Yes
The public id is the name used as a title for the media you want to call. This can be a single string like "example" or include your folder structure like "test/example"
transformations
Object
No
Check out all the transformations you can apply to your images here