# useResponsiveValue

## Specification

Returns a value based on the given breakpoint-value pairs. Whenever viewport matches a given breakpoint, its associated value is returned.  Returns the default value, if any, when no breakpoints are matched.

## Definition

```typescript
type useResponsiveValue<T> = (
  breakpoints: Record<string, T>,
  defaultValue?: T,
)
```

## Example

```jsx
import React from 'react'
import { useResponsiveValue } from 'atomic-layout'

export const ReadTime = ({ duration }) => {
  // Truncate a label caption based on the viewport
  const caption = useResponsiveValue(
    {
      // Use contraction on extra-small devices
      xs: 'min.',
    },
    // On all other breakpoints use the full label
    'minutes(s)'
  )
  
  return <p>Reading duration: {duration} {caption}</p>
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redd.gitbook.io/atomic-layout/api/hooks/use-responsive-value.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
