How do I trigger re-rendering when a class gets new data from a prop?

Viewed 26

Sorry for the awkward title, I'm not entirely sure how to word this question.

I have code that has two classes: Class "BLE" gets Bluetooth data and has to be running in top level at all times. Class "DeviceScreen" has components that need change whenever the bluetooth data updates. I pass the data into "DeviceScreen" as a prop like this:

this.props.route.params.myBLE

While "DeviceScreen" is able to get the data whenever the state re-renders, I can't figure out how to trigger the re-render whenever the data in "BLE" updates. How do I trigger re-rendering when a class gets new data from a prop?

1 Answers

you can try

componentDidUpdate(prevProps) {
  if (prevProps.propA !== this.props.propA) {
    // ... do effect
  }
}
Related