0

I don't know whether this is possible in React or not as I am a novice React developer. What I want is to call a function when the attribute (data-link) of my input element changes. I use componentDidUpdate but it triggers whenever any component changes.

I just want to call componentDidUpdate whenever there is any change in the specific attribute of a specific element.

halfer
  • 19,824
  • 17
  • 99
  • 186
Pranay kumar
  • 1,983
  • 4
  • 22
  • 51
  • so basically you can set a state within your component that will change when the there is any change in the specific attribute of a specific element, and within the componentDidUpdate you check the status if this state so for example if it is false that means that the change was done ion another element. – Farhani Walid May 20 '20 at 03:26

1 Answers1

0

I think the best option is to check if the specific value is changed __(the one you want to call the function on change), you can use

if (prevState.attribute !== this.state.attribute) {()=>callFunction}

then the callFunction is only called when there is a change in the attribute state.

halfer
  • 19,824
  • 17
  • 99
  • 186