Skip to content

Commit

Permalink
Timer: fix too many renders error when using ?progress (#305)
Browse files Browse the repository at this point in the history
* Timer: fix too many renders error when using ?progress
  • Loading branch information
markspolakovs authored Mar 6, 2023
1 parent 7d2b88b commit 48bfe47
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions client/src/features/viewers/timer/Timer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ const formatOptions = {
export default function Timer(props) {
const { general, pres, title, time, viewSettings } = props;
const { shouldRender } = useRuntimeStylesheet(viewSettings?.overrideStyles && overrideStylesURL);
const [elapsed, setElapsed] = useState(true);

const [searchParams] = useSearchParams();
const [elapsed, setElapsed] = useState(() => {
// eg. http://localhost:3000/timer?progress=up
// Check for user options
// progress: selector
// Should be 'up' or 'down'
const progress = searchParams.get('progress');
return progress === 'up';
});

const [isMirrored] = useAtom(mirrorViewersAtom);

useEffect(() => {
Expand All @@ -36,17 +45,6 @@ export default function Timer(props) {
return null;
}

// eg. http://localhost:3000/timer?progress=up
// Check for user options
// progress: selector
// Should be 'up' or 'down'
const progress = searchParams.get('progress');
if (progress === 'up') {
setElapsed(true);
} else if (progress === 'down') {
setElapsed(false);
}

const clock = formatTime(time.clock, formatOptions);
const showOverlay = pres.text !== '' && pres.visible;
const isPlaying = time.playstate !== 'pause';
Expand Down

0 comments on commit 48bfe47

Please sign in to comment.