1637
const onClick = useEffectEvent(() => {
1638
showNotification(theme);
1639
});
1640
+ // error message 1
1641
const onClick2 = () => { onClick() };
1642
+ // error message 2
1643
const onClick3 = useCallback(() => onClick(), []);
1644
+ // error message 3
1645
+ const onClick4 = onClick;
1646
return <>
1647
+ {/** error message 4 */}
1648
+ <Child onClick={onClick}></Child>
1649
<Child onClick={onClick2}></Child>
1650
<Child onClick={onClick3}></Child>
1651
</>;
1652
}
1653
`,
1654
+ // Explicitly test error messages here for various cases
1655
errors: [
1649
- useEffectEventError('onClick', true),
1650
- useEffectEventError('onClick', true),
1656
+ `\`onClick\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
1657
+ 'Effects and Effect Events in the same component.',
1658
+ `\`onClick\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
1659
+ 'Effects and Effect Events in the same component.',
1660
+ `\`onClick\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
1661
+ `Effects and Effect Events in the same component. ` +
1662
+ `It cannot be assigned to a variable or passed down.`,
1663
+ `\`onClick\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
1664
+ `Effects and Effect Events in the same component. ` +
1665
+ `It cannot be assigned to a variable or passed down.`,
1666
],
1667
},
1668
],
1729
return {
1730
message:
1731
`\`${fn}\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
1717
- `the same component.${called ? '' : ' They cannot be assigned to variables or passed down.'}`,
1732
+ 'Effects and Effect Events in the same component.' +
1733
+ (called ? '' : ' It cannot be assigned to a variable or passed down.'),
1734
};
1735
}
1736