Skip to content

Snackbar duration bug #3486

@suleymanbariseser

Description

@suleymanbariseser

Current behaviour

Duration prop does not work in Snackbar. Timer resets whenever onDismiss function updates. It means even when a state changes it will reset the timer.

Expected behaviour

Duration prop must be independent from any other state and prop.

How to reproduce?

Here is a snack where this issue can be reproducable.

What have you tried so far?

The problem about this is adding onDismiss into dependency array of the useEffect which handles the timer in the Snackbar component. However, this is needed because onDismiss must be triggered whenever time will be over and we must trigger the latest version of onDismiss function. The problem can be solved by moving the logic inside the useEffect into event functions and trigger them in the useEffect whenever visible updates. The problem and the solution is described here in detail. In the detailed url, it is solved by useEvent but useEvent is still an experimental hook. That's why, an alternative hook(useEventCallback) can be used to achieve the same goal.

Your Environment

software version
react-native-paper 4.9.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions