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

[bug] no-direct-set-state-in-use-effect should not lint for code in useLayoutEffect #839

Closed
Jack-Works opened this issue Oct 10, 2024 · 0 comments
Labels
Status: Released The issue has been released Type: Bug Something isn't working

Comments

@Jack-Works
Copy link

Describe the bug

This is the official use case in the React docs, you cannot do it another way.

https://react.dev/reference/react/useLayoutEffect

function Tooltip() {
  const ref = useRef(null);
  const [tooltipHeight, setTooltipHeight] = useState(0); // You don't know real height yet

  useLayoutEffect(() => {
    const { height } = ref.current.getBoundingClientRect();
    setTooltipHeight(height); // Re-render now that you know the real height
  }, []);

  // ...use tooltipHeight in the rendering logic below...
}

Reproduction

No response

Expected behavior

No response

Platform and versions

"@eslint-react/eslint-plugin": "^1.14.3"

Stack trace

No response

Additional context

No response

@Rel1cx Rel1cx added the Type: Bug Something isn't working label Oct 10, 2024
@Rel1cx Rel1cx closed this as completed in 6bda4bf Oct 10, 2024
@Rel1cx Rel1cx added the Status: Released The issue has been released label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Released The issue has been released Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants