Skip to content

Replace useResponsiveValue by useResponsiveProps #283

@kettanaito

Description

@kettanaito

Please see the first comment under this issue for more accurate issue status.

What:

I suggest that useResponsiveValue hook respected the behavior system used in responsive props. This means that a breakpoint without an explicit behavior implies the default one (i.e. "up"). Breakpoints (properties) accept an explicit behavior that changes the way their values are applied.

import { useResponsiveValue } from 'atomic-layout'

const Component = () => {
  const data = useResponsiveValue({
    sm: 2,
    lg: 3,
  })

  return <p>{data}</p>
}

The example above would assign the following values:

xs - undefined
sm - 2
md - 2 (stretches, since "sm" has no behavior, which implies the default "up")
lg - 3 (explicit override)
xl - 3 (stretches similarly to "md")

Why:

Current implementation of useResponsiveValue treats all properties as with "only" behavior. This makes it hard for a value to persist between breakpoints and requires to repeat it.

import { useResponsiveValue } from 'atomic-layout'

const Component = () => {
  const data = useResponsiveValue({
    md: 2,
    lg: 2,
  })

  return <p>{data}</p>
}

Using the second parameter of defaultValue doesn't help, because it's assign on any matches outside of the given breakpoint names. It's generally meant for a different behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestneeds:discussionFurther information is requestedscope:calculationThis issue relates to the calculation logic

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions