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.
useBreakpoint will be called on initial render, when useBreakpointChange is 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:
What:
I suggest to add the following React hook:
Why:
It should replace current
useBreakpointChangehook with both: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
useStateupdating its value onuseBreakpointChangecallback. With the suggested hook added it can be written in a single hook declaration.Usage example:
Getting a breakpoint name
Reacting to breakpoint change
How:
useBreakpointChangeuseBreakpoint