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

isPending() state isn't reset to false if the tracked value hasn't changed. #178

Closed
wkd-kapsule opened this issue Jul 17, 2024 · 4 comments · Fixed by #180
Closed

isPending() state isn't reset to false if the tracked value hasn't changed. #178

wkd-kapsule opened this issue Jul 17, 2024 · 4 comments · Fixed by #180

Comments

@wkd-kapsule
Copy link

Hi! I have a simple implementation of the hook where I track the value of an input and do something after a delay if the value has changed. The value of the input is used somewhere else on the screen. So I use the isPending() method to display an animation to inform the user that their input is being registered, before they can see any change on the screen. Basic UX improvement.

Everything is fine except for the case where you start typing something only to erase it and leave the input's value unchanged. Then the isPending() value stays true. Here are a video showing it in action and a snippet of my code. Note that the two <span /> at the end are meant to show that the issue doesn't come from the implementation inside my <Input /> component. The isPending() remains "frozen" even in the component where the useDebounce() is declared.

Any help would be greatly appreciated, thanks!

Enregistrement.de.l.ecran.2024-07-17.200947.mp4
// more irrelevant things here...
const [input, setInput] = useState(p.value.text)
const [debouncedValue, bouncing] = useDebounce(input, 500)

return (
  <InputWrapper>
    <Label htmlFor={`${p.label}-${id}`} children={p.label} />
    <RadioButtons
      small
      name={`textAlign-${id}`}
      buttons={textAlignRadio}
      onChange={handleTextAlign}
    />
    <Input
      textareaRef={areaRef}
      isTextarea
      noLabelTag
      name={p.label + id}
      className="leading-normal font-xsmall weight-medium"
      dots={bouncing.isPending()}
      defaultValue={p.value.text}
      onChange={e => setInput(e.target.value)}
    />
    {bouncing.isPending() && (
      <span className="text-micro">Bouncing</span>
    )}
    {!bouncing.isPending() && (
      <span className="text-micro">Not Bouncing</span>
    )}
  </InputWrapper>
)
@xnimorz
Copy link
Owner

xnimorz commented Jul 20, 2024

Hey @kapsule-studio
thanks for your feedback.

I'll take a look at it in upcoming week

@xnimorz
Copy link
Owner

xnimorz commented Jul 28, 2024

Fixed in #180

@xnimorz
Copy link
Owner

xnimorz commented Jul 28, 2024

[email protected]

@wkd-kapsule
Copy link
Author

Thanks for working on it. Unfortunately, there is still a misbehavior 😅 Now, if I type something and quickly erase it but keep typing, when the value gets back to its initial state, isPending() is set to false even though I'm still typing.

It is subtle but you can notice it: value starts as Account. If I type ..., erase it and keep typing, right when the value goes from Account. to Account, which was the initial state, isPending() is set to false whereas I am still typing. You can tell by the animation stopping when the value gets back to its initial state just before starting again If I'm still typing. I expect it to stop only when the debounce delay is passed, no matter the current value.

Note: I seem to be one of the few to be disturbed by that. The project I'm working on won't be finished before a long time.
Don't bother yourself with that issue if you have better to do. Enjoy your holiday, family, hobbies, I'll be just fine.

Still.bugging.mp4

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

Successfully merging a pull request may close this issue.

2 participants