Prune the story progress effect's dependency list

This commit is contained in:
Josh Perez 2022-04-20 19:38:38 -04:00 committed by GitHub
parent 774246b6e2
commit 8c4b875dca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 43 deletions

View file

@ -176,21 +176,11 @@ export const StoryViewer = ({
};
}, [attachment]);
const [styles, spring] = useSpring(() => ({
from: { width: 0 },
to: { width: 100 },
loop: true,
}));
// Adding "currentStoryIndex" to the dependency list here to explcitly signal
// that this useEffect should run whenever the story changes.
useEffect(() => {
spring.start({
config: {
duration: storyDuration,
},
const [styles, spring] = useSpring(
() => ({
from: { width: 0 },
to: { width: 100 },
loop: true,
onRest: {
width: ({ value }) => {
if (value === 100) {
@ -198,12 +188,25 @@ export const StoryViewer = ({
}
},
},
}),
[showNextStory]
);
// We need to be careful about this effect refreshing, it should only run
// every time a story changes or its duration changes.
useEffect(() => {
spring.start({
config: {
duration: storyDuration,
},
from: { width: 0 },
to: { width: 100 },
});
return () => {
spring.stop();
};
}, [currentStoryIndex, showNextStory, spring, storyDuration]);
}, [currentStoryIndex, spring, storyDuration]);
useEffect(() => {
if (hasReplyModal) {