N
N
nelu36152020-07-01 14:17:14
React
nelu3615, 2020-07-01 14:17:14

React Hooks, Twilio-video, how to set dominantSpeaker screen only 2 seconds after state changes?

const Room = ({....
....
const [dominantSpeaker, setDominantSpeaker] = useState(null);
.....
useEffect(() => {
if (dominantSpeaker) {
console.log('dommm', dominantSpeaker);
setParticipants(prevParticipants => [
dominantSpeaker,
...prevParticipants.filter(participant => participant !== dominantSpeaker),
]);
}
}, [dominantSpeaker]);

now screen changes as soon as state changes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil, 2020-07-01
@TchernyavskD

In the user effect with the necessary timeout, while with the dependence of your state, which must be taken into account in the change, while taking into account the unmount and, if anything, cleaning the timeout

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question