-
-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Labels
featureneeds:discussionFurther information is requestedFurther information is requestedscope:calculationThis issue relates to the calculation logicThis issue relates to the calculation logic
Milestone
Description
This is an API refinement story preparation for the first major release. It introduces a breaking change and will be released respectively.
What:
I suggest to add the following React hook:
type UseBreakpoint<T> = ((breakpointName: string) => T) => [string, T]Why:
It should replace current useBreakpointChange hook with both:
- Information about the current breakpoint (first argument in a tuple),
- Updater function that is called on each breakpoint change (mirroring of
useBreakpointChange. useBreakpointwill be called on initial render, whenuseBreakpointChangeis not.
Main motivation is that it's currently lengthy to know which breakpoint is met. It requires to have useState updating its value on useBreakpointChange callback. With the suggested hook added it can be written in a single hook declaration.
Usage example:
Getting a breakpoint name
import { useBreakpoint } from 'atomic-layout'
const Component = () => {
const [breakpointName] = useBreakpoint()
return <p>You are on {breakpointName} screen</p>
}Reacting to breakpoint change
import { useBreakpoint } from 'atomic-layout'
const dataMap = {
xs: 'one',
sm: 'two'
}
const Component = () => {
const [breakpointName, data] = useBreakpoint((breakpointName) => {
return dataMap[breakpointName]
})
return <p>You are on {breakpointName} screen with {data}</p>
}How:
- Deprecate
useBreakpointChange - Add
useBreakpoint - Add unit tests
Metadata
Metadata
Assignees
Labels
featureneeds:discussionFurther information is requestedFurther information is requestedscope:calculationThis issue relates to the calculation logicThis issue relates to the calculation logic