web icon indicating copy to clipboard operation
web copied to clipboard

Unexpected regexp behavior in useThrottledEffect demo

Open alev000 opened this issue 2 years ago • 1 comments

This demo for useThrottledEffect exhibits some strange behavior. To reproduce, try slowly entering the string a1aaaaaa into the text box, and you'll see the status toggle repeatedly between "no digits" and "has digits".

I think the regexp in this line should drop the "global" flag. From these docs:

JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y). They store a lastIndex from the previous match.

alev000 avatar Jan 03 '24 19:01 alev000

Same for the useDebouncedEffect demo

Relevant code search link: https://github.com/search?q=repo%3Areact-hookz%2Fweb+%2F%5C%2Fg%5Cb%2F&type=code

alev000 avatar Jan 03 '24 19:01 alev000