Skip to content

Stale data passed to promiseFn when using watchFn #180

Closed
@salolivares

Description

@salolivares

Potentially related #4

Issue
When watching for a variable change using watchFn, the react async hook properly re-runs promiseFn but with old props passed in.

Expected
promiseFn should have received the new props on re-run.

Example
See https://codesandbox.io/s/jovial-grothendieck-3xth2
In the example above the first render console.logs the following:

in function  grapefruit 
in promise grapefruit 
in function  grapefruit 
Rerun promise? 
false

All is good! But once we change the fruit, we get the following:

in function  lime 
Rerun promise? 
true
in promise grapefruit  <---- should have been lime
in function  lime 
Rerun promise? 
false

And if we run it again:

in function  coconut 
Rerun promise? 
true
in promise lime    <---- should have been coconut
in function  coconut 
Rerun promise? 
false

Am I missing something with the way hooks work or overlooking something simple? Any help will be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions