-1

I have to use key property for react element to be able to rerender it correctly.

<Element key={value} />

The problem is that I want it to rerender depending on multiple values like:

<Element key={value || value2} />

But I see it is not even checking value2 so when it changes it is not rerendering. How can I do that? Is there any other way?

Sowam
  • 1,674
  • 3
  • 12
  • 30
  • 1
    I am not sure but maybe you can say `````` – Norse Apr 08 '21 at 09:52
  • I cannot think of any reason why you should need a variable `key` prop for your element; is it possible this is a case of [XY problem](https://en.wikipedia.org/wiki/XY_problem)? Maybe it would be beneficial if you share more details about what you are trying to do as well as the code you are using. – secan Apr 08 '21 at 10:04

1 Answers1

0

Thank you for help guys. Changing it to a string with both values works.

<Element key={`${value}-${value2}`} />
Sowam
  • 1,674
  • 3
  • 12
  • 30