-
Notifications
You must be signed in to change notification settings - Fork 55
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
Couldn't use match index (replace function second arg) as a key #18
Comments
Hey @kadmil thanks for opening the issue. Hm, I'm still not clear on what causes duplicate keys. If you are using |
Unfortunately, prefixing doesn't solve this. What happens here is: replacer for the first regex divides original string to an array like If I run
Note two repeating keys As I said, my actual workarounds are at least cumbersome. |
Very handy lib, thanks ! I'm having the same issue with duplicate keys being produced. I've created a minimal Codesandox demonstrating the issue: https://codesandbox.io/s/5p570pnwx |
Hm... we could provide a unique
That would stop react from complaining, but it would also not do what keys are supposed to do which is remain consistent from render to render (provide a "stable identity" as the react docs say) so it feels like a duck tape solution to me. I like the idea of having a "running" or "total" index for every time the replacement function is called, as suggested by @kadmil (sorry forgot to respond before!) but I'm not sure where that index would come from, we could keep track of an index internally but it's not clear to me how that would provide a stable identity to the rendered items, so we might have the same problem as above where it just gets react to be quiet but doesn't provide the real benefit of using keys. |
Hello! First of all, thanks for the nicest replacer for react. )))
There's a thing. I want to use index parameter in replacer function as a key for react to be happy and render all my replaced texts. If I do two replaces at a time, say
Then, for initial string in pattern of
${match_second_regex_1} ${match_first_regex} ${match_second_regex_2}
replacer would set the same key for both second regex matches, and then react would blow up swallowing the second match span entirely.What I did for now was embedding
offset
param from the new lib version, but that's not the real solution obviously.What I could do right now is to call
.reduce
with running total index and not calling reactStringReplace on array, but that way I'm missing perfect lib api use-case. From the api point of lib, I could think of two possible things: 1) having second argument for replace function be running index, and not exact string match index; or 2) having another one argument with that index for replacer function.First option would almost definitely break someone's workflow (https://xkcd.com/1172/), second one makes api clunky (arghhh, fourth parameter).
What's your opinion on this? I would be happy to help with code, but messing with api without your decision feels not a way to go.
The text was updated successfully, but these errors were encountered: