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

Reactive event handlers are not working #59

Open
2 tasks done
ostapoff opened this issue Oct 25, 2022 · 1 comment
Open
2 tasks done

Reactive event handlers are not working #59

ostapoff opened this issue Oct 25, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@ostapoff
Copy link

Checks

Version

0.7.12 and earlier

Description

event handlers using state do not work. Bound once during the first render never reassigned later:

  const [counter, setCounter] = useState(0);
  const onMove = useCallback(() => {
    console.log("should increment but always 0:", counter);
    setCounter((counter) => counter + 1);
  }, [counter]);


<Splide onMove={onMove}>

Reproduction Link

https://codesandbox.io/s/event-forked-mmd2vd

Steps to Reproduce

try to use a component state in event handler. It will be always equal to the initial state.

Expected Behaviour

<Splide> component should track the event handler changes

@ostapoff ostapoff added the bug Something isn't working label Oct 25, 2022
@ostapoff ostapoff changed the title Reactive event handler are not working Reactive event handlers are not working Oct 25, 2022
@ostapoff
Copy link
Author

useEvent can solve the problem but it will be available only in next 18.3.0 React
solution with useEvent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant