@@ -8,7 +8,13 @@ import Row from 'react-bootstrap/Row'
8
8
9
9
// Local Imports
10
10
import '../Home.css'
11
- import { connectToROS , createROSService , createROSServiceRequest , subscribeToROSTopic } from '../../../ros/ros_helpers'
11
+ import {
12
+ connectToROS ,
13
+ createROSService ,
14
+ createROSServiceRequest ,
15
+ subscribeToROSTopic ,
16
+ unsubscribeFromROSTopic
17
+ } from '../../../ros/ros_helpers'
12
18
import { convertRemToPixels , scaleWidthHeightToWindow } from '../../../helpers'
13
19
import {
14
20
FACE_DETECTION_IMG_TOPIC ,
@@ -63,7 +69,13 @@ const BiteInitiation = (props) => {
63
69
[ setDetectedMouthCenter , setMouthDetected , readyForBite ]
64
70
)
65
71
useEffect ( ( ) => {
66
- subscribeToROSTopic ( ros . current , FACE_DETECTION_TOPIC , FACE_DETECTION_TOPIC_MSG , faceDetectionCallback )
72
+ let topic = subscribeToROSTopic ( ros . current , FACE_DETECTION_TOPIC , FACE_DETECTION_TOPIC_MSG , faceDetectionCallback )
73
+ // In practice, because the values passed in in the second argument of
74
+ // useEffect will not change on re-renders, this return statement will
75
+ // only be called when the component unmounts.
76
+ return ( ) => {
77
+ unsubscribeFromROSTopic ( topic , faceDetectionCallback )
78
+ }
67
79
} , [ faceDetectionCallback ] )
68
80
69
81
// Create the ROS Service. This is created in local state to avoid
0 commit comments