-
-
Notifications
You must be signed in to change notification settings - Fork 294
Description
Summary
Hello! I am using the library alongside with custom controlElements
and in my implementation of valueEditor
, I'm facing state issues that seem to be caused by non-optimal use of the key
property during iterations.
Description
Let's say I have two rules, rule#1
and rule#2
. When I delete the rule#1
thanks to the Remove rule
button, it appears that React tries to use the UI instance of the deleted rule#1
to put the rule#2
's content into it (e.g. all the props including field
, operator
, value
..). To illustrate that, in the default ValueEditor
, I've tested to add console.log
of the operator
and of the previous render's operator
, and here is what's happening when deleting the first rule:
=> React seems to be trying to fill the Last name in
rule's content into the instance of the former First name begins with
rule.
After doing some digging into the library's source code, it appears in RuleGroup.tsx#line304 that when iterating on rules
, you use indexes as the key
to repeated elements.
React recommends to use unique identifiers as keys: indeed, if the order can change, using indexes "can negatively impact performance and may cause issues with component state", and that's precisely the problem I'm encountering.
Suggestion
Would that be possible for you to use unique identifiers for this key, such as the rule's id for example?