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

⚗️ [useVurttle] Experiment with throttle hook #11

Merged
merged 3 commits into from
Apr 3, 2024

Conversation

beefchimi
Copy link
Owner

I am now exporting useTimeout() and useVurttle() hooks.

The idea of useVurttle() is something like this:

export function MyComponent() {
  const {listRef, listWidth, listHeight, virtualItems, updateItemHeight} = useVurtis({
    count: 20,
    minWidth: 100,
    gap: 10,
  });

  // Will flip back-and-forth between `true/false` during resize operations.
  // When `true`, you can refrain from additional computations - such as animations.
  const pending = useVurttle(listWidth);

  const itemsMarkup = virtualItems.map(
    ({order, top, left, width, height}, index) => {
      return (
        <li
          key={`Item-${order}`}
          ref={index === 0 ? updateItemHeight : undefined}
          style={{top, left, width}}
        >
          <span>{order}</span>
        </li>
      );
    },
  );

  return (
    <div>
      <p>Pending: {pending.toString()}</p>

      <ul ref={listRef} style={{height: listHeight}}>
        {itemsMarkup}
      </ul>
    </div>
  );
}

@beefchimi beefchimi self-assigned this Apr 3, 2024
Copy link

changeset-bot bot commented Apr 3, 2024

🦋 Changeset detected

Latest commit: bcdcc19

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
vurtis Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@beefchimi beefchimi merged commit 3643541 into main Apr 3, 2024
3 checks passed
@beefchimi beefchimi deleted the export-more-props branch April 3, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant