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

[Bug] onupdatefiles cannot get updated state while onaddfile can #198

Open
2 tasks done
tiantud opened this issue Feb 7, 2022 · 2 comments
Open
2 tasks done

[Bug] onupdatefiles cannot get updated state while onaddfile can #198

tiantud opened this issue Feb 7, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@tiantud
Copy link

tiantud commented Feb 7, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Have you updated FilePond and its plugins?

  • I have updated FilePond and its plugins

Describe the bug

Im using a select to control a state "mode" in react. Each time you update the select, the value in "mode" will be changed.

Im want to get the current state when the files are updated (added and deleted). For that I tried two events: onupdatefiles and onaddfile.

Expected: Both event can get the current state. Or at least, both of them get the same value.

Actuall: onaddfile got the updated value, onupdatefiles got always init value.

Reproduction

Codesandbox

  1. Open debug tool
  2. Swich the select, you should see something like "Previous mode: test2, setting mode: test1". Which means the state is actually updated.
  3. Upload any file. You should see three lines in logger:

onupdatefile got mode:
onaddfile got mode: test1
onupdatefile got mode:

which means:

  • the onupdatefile event got a empty state "mode", and its exactlly the init state
  • the onaddfile event got the updated state "mode"

Environment

- Device: PC
- OS: Windows 10
- Browser: Chrome 98, Firefox 96, Edge 98
@tiantud tiantud added the bug Something isn't working label Feb 7, 2022
@rikschennink rikschennink transferred this issue from pqina/filepond Feb 7, 2022
@tiantud
Copy link
Author

tiantud commented Feb 7, 2022

I tried to find another way to use the event onupdatefiles, because its the only one event which supports sync-uploading.

First try, but failed

Reproduction

In this sandbox, I am using the conditional rendering to render different FilePond for different state. But it turns out, that even the FilePond component is changed, the registed event function stays the same.

codesandbox

  1. Open debug tool
  2. Swich the select, you should see something like "Previous mode: test2, setting mode: test1". Which means the state is actually updated.
  3. Swich to "test1", you can see "this is test1". That is the FilePond label.
  4. Upload any file. You should see three lines in logger:

onupdatefile got mode: test1
onaddfile got mode: test1
onupdatefile got mode: test1

  1. Swich to "test2", you can see "this is test2". Means the Component is re-rendered.
  2. Upload any file. You should see three lines in logger:

onupdatefile got mode: test1
onaddfile got mode: test2
onupdatefile got mode: test1

which means: The event function of onupdatefile is not updated, but the one of onaddfile is updated.

Second try, succeed

Reproduction

Now the two FilePonds are rendered in two seperated condition-section.

codesandbox

  1. Open debug tool
  2. Swich the select, you should see something like "Previous mode: test2, setting mode: test1". Which means the state is actually updated.
  3. Swich to "test1".
  4. Upload any file. You should see three lines in logger:

onupdatefile got mode: test1
onaddfile got mode: test1
onupdatefile got mode: test1

  1. Swich to "test2".
  2. Upload any file. You should see three lines in logger:

onupdatefile got mode: test2
onaddfile got mode: test2
onupdatefile got mode: test2

@diva-D
Copy link

diva-D commented Oct 5, 2022

+1, I'm also getting this issue.

Using onupdatefiles always returns the intial state, whereas onaddfile returns the updated state values.

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

2 participants