Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New hooks for element size tracking #413

Merged
merged 13 commits into from
Nov 19, 2021
Merged

feat: New hooks for element size tracking #413

merged 13 commits into from
Nov 19, 2021

Conversation

tassoevan
Copy link
Collaborator

@tassoevan tassoevan commented Mar 9, 2021

  • I have read the Contributing Guide
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have labeled the PR correctly with the related package
  • I have run Loki's visual regression tests (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Proposed changes (including videos or screenshots)

The useResizeObserver() hook has a remarkable flaw when used as a replacement for container queries for styling: its initial state is asynchronously set. This pull request introduces two distinct hooks, useBorderBoxSize() and useContentBoxSize(), which must be used instead to avoid flickering in components that need to know a element size to render valid JSX. E.g.:

const MyComponent = () => {
  const ref = useRef();
  const { inlineSize } = useContentBoxSize(ref);
  
  return <div ref={ref}>
    {inlineSize > 100 ? 'Greather than 100px' : 'Too small'}
  </div>;
};

@tassoevan tassoevan requested a review from a team March 9, 2021 22:23
@tassoevan tassoevan requested review from a team and removed request for a team April 26, 2021 21:38
@tassoevan
Copy link
Collaborator Author

@ggazzo Please review, sir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants