Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(breakpoints): races in useViewportWidth (#114)
The main fix here is changing the initial state from null to window.innerWidth, so that there isn't a useless transition from (for example) `useDown('md') = true` to `useDown('md') = false` when the application loads. Depending on the application, the rerendering penalty can be heavy. While we're here, notice that we can make a couple related changes: First, since the initial state is set properly, we don't need a layout effect, instead we can use a normal effect. Second, swap the order of listener and setWidth to avoid the tiny race between them.
- Loading branch information