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

useIMask doesn't add event listener accept & complete on some cases #1078

Open
baran-ozer opened this issue Sep 20, 2024 · 0 comments
Open

Comments

@baran-ozer
Copy link

Describe the bug
When I render my dom elements optionally I have deteced that useIMask hook can't add event listener to my input.

To Reproduce
You can see this error on reactplayground. IMask on input works correctly but it doesn't update IMask value since there is no accept and complete event on my input. When dom loads IMask

useEffect(() => {
if (!maskRef.current) return;
const mask = maskRef.current;
mask.on('accept', _onAccept);
mask.on('complete', _onComplete);
return () => {
mask.off('accept', _onAccept);
mask.off('complete', _onComplete);
};
}, [_onAccept, _onComplete]);
this hook above triggers once but imask.ref is empty so it can't attach event listeners, then on second render(when isLoading state setted to false on my playground code) this hook never triggers again.

Expected behavior
A clear and concise description of what you expected to happen.

Environment:

  • OS: [macOS]
  • Browser: [chrome]
  • Version: [128.0.6613.138]
  • IMask version: [7.6.1]
  • Framework/plugin version : [React 18.2.0]

Additional context
I have fixed this issue by updating this dependency hook:

useEffect(() => {
if (!maskRef.current) return;
const mask = maskRef.current;
mask.on('accept', _onAccept);
mask.on('complete', _onComplete);
return () => {
mask.off('accept', _onAccept);
mask.off('complete', _onComplete);
};
}, [_onAccept, _onComplete]);

I can open a PR for this if you agree that this is a bug.

@baran-ozer baran-ozer changed the title useIMask dooes't add event listener accept & complete on some cases useIMask doesn't add event listener accept & complete on some cases Sep 20, 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

No branches or pull requests

1 participant