Closed gpbmike closed 8 years ago
Hey @gpbmike, thanks for the pull request. Thanks for this. I totally overlooked the need for keys in the replacement function.
The only thing I would change is to use something besides the match
as the key. It's possible for a match to be the same for two replacements, which means both JSX tags would get the same key, which would lead to only one being rendered.
Could you change the key
prop to use the index instead of the match? The callback function is passed the index in addition to the match:
(match, i) => <div key={i}>...</div>
Let me know if that doesn't make sense
I copied that bit from the example (https://github.com/iansinnott/react-string-replace/blob/master/example/index.js#L22). In my own code I have something more akin to key={
${match}-${i}}
. I can change it in both places if you'd like.
Ah yes, thanks for pointing that out. I just updated the example code to use something like your approach. Yeah I'm happy to merge this PR if you update those keys to use a combination of match
and i
.
Followed your lead from example.
Thanks 😄