I have two components. I pass handleCurrentAudioInputDeviceLabel
to Publisher.js where
I setCurrentAudioInputDeviceLabel
. You can see that I am missing the dependency
setCurrentAudioInputDeviceLabel
in useEffect. However, as soon I add it my component starts to re-render more often.
I thought about useCallback
, but once I tried that, my linter says I have to add more than just currentAudioInputDeviceLabel
.
VideoMeeting.js
const handleCurrentAudioInputDeviceLabel = (currentAudioInputDeviceLabel) => {
setCurrentAudioInputDeviceLabel(currentAudioInputDeviceLabel);
};
<Publisher
setCurrentAudioInputDeviceLabel={
handleCurrentAudioInputDeviceLabel
}
/>
Publisher.js
useEffect(() => {
// Prevent to set audio source before publisher exists
if (!publisherRef.current) {
return;
}
const handleError = (error) =>
onError(error, INITIATOR_AUDIO_DEVICE_PUBLISHER);
publisherRef.current
.setAudioSource(currentAudioInputDevice.deviceId)
.then(() => {
setCurrentAudioInputDeviceLabel(currentAudioInputDevice.label);
})
.catch((error) => {
handleError(error);
});
}, [currentAudioInputDevice, onError]);