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

[Linting] Fixed useExhaustiveDependencies in biome #3197

Merged
merged 15 commits into from
Oct 8, 2024
Merged

Conversation

KenAJoh
Copy link
Collaborator

@KenAJoh KenAJoh commented Oct 3, 2024

Description

Some were still relevant, but most could be updated/refactored

As for the iFrame change in sanity, instead of resolving the useEffect we now use sanity-plugin-iframe-pane (https://www.sanity.io/plugins/iframe-pane) that solves this for us. All we need to do is provide it an URL like we already did. Will need to test this in dev to make sure it still works as intended

Performance Optimizations:

  • Optimized memoization for rerendering in some components (.changeset/bright-meals-repair.md).

Refactoring and Cleanup:

  • Removed unnecessary dependencies in useEffect hooks in multiple files:
    • @navikt/aksel-icons/figma-plugin/src/ui/App.tsx
    • @navikt/core/react/src/form/combobox/Input/Input.context.tsx
    • @navikt/core/react/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx
    • @navikt/core/react/src/form/combobox/customOptionsContext.tsx
    • @navikt/core/react/src/modal/Modal.tsx
    • @navikt/core/react/src/overlays/dismissablelayer/DismissableLayer.tsx
    • @navikt/core/react/src/progress-bar/ProgressBar.tsx
    • @navikt/core/react/src/table/AnimateHeight.tsx
    • @navikt/core/react/src/util/TextareaAutoSize.tsx
    • @navikt/core/react/src/util/create-context.tsx
    • @navikt/core/react/src/util/hooks/descendants/descendant.stories.tsx

Component Checklist 📝

  • JSDoc
  • Examples
  • Documentation
  • Storybook
  • Style mappings (@navikt/core/css/config/_mappings.js)
  • Component tokens (@navikt/core/css/tokens.json)
  • CSS class deprecations (@navikt/aksel-stylelint/src/deprecations.ts)
  • Exports (@navikt/core/react/src/index.ts and @navikt/core/react/package.json)
  • New component? CSS import (@navikt/core/css/index.css)
  • Breaking change? Update migration guide. Consider codemod.
  • Changeset (Format: <Component>: <gitmoji?> <Text>. E.g. "Button: ✨ Add feature xyz.")

Copy link

changeset-bot bot commented Oct 3, 2024

🦋 Changeset detected

Latest commit: 3abd5e8

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

This PR includes changesets to release 7 packages
Name Type
@navikt/ds-react Patch
@navikt/ds-css Patch
@navikt/ds-tokens Patch
@navikt/ds-tailwind Patch
@navikt/aksel-icons Patch
@navikt/aksel Patch
@navikt/aksel-stylelint 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

Comment on lines 104 to 109
const isLimitReached = useMemo(() => {
return (
(!!maxSelected?.limit && selectedOptions.length >= maxSelected.limit) ||
(!isMultiSelect && selectedOptions.length > 0)
);
}, [maxSelected, selectedOptions, isMultiSelect]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's no expensive calculations here, I don't think useMemo will have any benefits in this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its memozied to avoid this useEffect from running all the time:

useEffect(() => {
    setHideCaret(isLimitReached);
  }, [isLimitReached, setHideCaret]);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since isLimitReached is a boolean, it will not change on each render, as opposed to an object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 🧠 🧠 🧠 🧠 🧠 🧠 TIL! So used to using bools in states like const [flag, setFlag]= useState.. where changing flag to the same value will cause useEffect from running that i didn't even know this

.changeset/bright-meals-repair.md Show resolved Hide resolved
Base automatically changed from biome-1-9-0 to main October 5, 2024 13:41
Copy link
Contributor

github-actions bot commented Oct 7, 2024

Storybook demo

6637a2a3a | 90 komponenter | 141 stories

@KenAJoh KenAJoh merged commit aac12fe into main Oct 8, 2024
3 checks passed
@KenAJoh KenAJoh deleted the biome-linting-10-2024 branch October 8, 2024 07:06
@github-actions github-actions bot mentioned this pull request Oct 8, 2024
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.

2 participants