I understand useEffect
runs every time when my component is rendered. I am currently integrating a VideoConference application which creates after initialization an object called publisher
. That publisher
can be updated. For example, I can deactivate video etc.
I created two buttons that change the state of audio
and video
to either 0 or 1. I then pass these values to the component OTPublisher
. The part I am confused about is if I actually should/need to use useEffect
? It works both ways, also if I just insert it in the component directly without useEffect
.
<OTPublisher
video={video}
audio={audio}
completionHandler={completionHandler}
>
OTPublisher.js
useEffect(() => {
if (publisher) {
audio ? publisher.publishAudio(true) : publisher.publishAudio(false);
video ? publisher.publishVideo(true) : publisher.publishVideo(false);
}
});
///
if (publisher) {
audio ? publisher.publishAudio(true) : publisher.publishAudio(false);
video ? publisher.publishVideo(true) : publisher.publishVideo(false);
}