简体   繁体   中英

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

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?

you can try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM