yairEO / tagify

🔖 lightweight, efficient Tags input component in Vanilla JS / React / Angular / Vue
https://yaireo.github.io/tagify/
Other
3.48k stars 429 forks source link

React MixedTags input only saves the initial state passed to it #1316

Closed khaziq-sfy034 closed 4 months ago

khaziq-sfy034 commented 5 months ago

Prerequisites

React issue template: https://codesandbox.io/p/sandbox/tagify-react-issue-template-forked-dt6twg?file=%2Fsrc%2Findex.js

Explanation

So I have provided an example that shows some weird behaviour. What I am trying to do is to loop though a list of sections, each section has multiple options. So I update the value for the speaker using the dropdown. But when I type someting in the input it logs the old state (the initial state), instead I should be getting the updated state for each section along with the changed values.

For example:

So tagify stores only the initial state and updates it, so you lose the updated state that has been done by other component if you try to update the text of the section inside the onChange function.

I have tried the onChange with and without useCallback hook but the behaviour is same.

yairEO commented 5 months ago

The actual issue is that callback functions references cannot be updated or removed after Tagify is initialized via the React port.