Return to Sky UI homepage

useResponsiveProps

import { useResponsiveProps } from '@sky-uk/ui-core';

The useResponsiveProps hook can be used to makes props respond to different screen sizes.

Basic usage

With multiple props

Use with asset URLs

When using this hook to switch between asset URLs, if modifying the URL (e.g. to add query params) then you will need to guard against the hook's initial undefined return, to avoid unwanted network requests:

You do not need to guard against the above if using the asset URL returned from the hook "as-is", because React will just omit the src attribute altogether when given undefined.