Skip to content

Commit

Permalink
Add another test for supporting linting useXEffect hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Pettengill committed Apr 11, 2020
1 parent 70f95c9 commit 47994e7
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4170,6 +4170,36 @@ const tests = {
],
options: [{additionalHooks: 'useLayoutEffect_SAFE_FOR_SSR'}],
},
{
code: `
function MyComponent() {
const myRef = useRef();
useIsomorphicLayoutEffect(() => {
const handleMove = () => {};
myRef.current.addEventListener('mousemove', handleMove);
return () => myRef.current.removeEventListener('mousemove', handleMove);
});
return <div ref={myRef} />;
}
`,
output: `
function MyComponent() {
const myRef = useRef();
useIsomorphicLayoutEffect(() => {
const handleMove = () => {};
myRef.current.addEventListener('mousemove', handleMove);
return () => myRef.current.removeEventListener('mousemove', handleMove);
});
return <div ref={myRef} />;
}
`,
errors: [
`The ref value 'myRef.current' will likely have changed by the time ` +
`this effect cleanup function runs. If this ref points to a node ` +
`rendered by React, copy 'myRef.current' to a variable inside the effect, ` +
`and use that variable in the cleanup function.`,
],
},
{
// Autofix ignores constant primitives (leaving the ones that are there).
code: normalizeIndent`
Expand Down

0 comments on commit 47994e7

Please sign in to comment.