Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrookes committed Jul 6, 2024
1 parent 5baf7e9 commit 330cc31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
24 changes: 4 additions & 20 deletions docs/data/material/components/progress/LinearBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ export default function LinearBuffer() {
const [progress, setProgress] = React.useState(0);
const [buffer, setBuffer] = React.useState(10);

const bufferRef = React.useRef(() => {});
React.useEffect(() => {
bufferRef.current = () => {
if (buffer < 100) {
const newBuffer = buffer + 1 + Math.random() * 10;
setBuffer(newBuffer > 100 ? 100 : newBuffer);
}
};
});

const progressRef = React.useRef(() => {});
React.useEffect(() => {
progressRef.current = () => {
Expand All @@ -24,20 +14,14 @@ export default function LinearBuffer() {
setBuffer(10);
} else {
setProgress(progress + 1);
if (buffer < 100 && progress % 5 === 0) {
const newBuffer = buffer + 1 + Math.random() * 10;
setBuffer(newBuffer > 100 ? 100 : newBuffer);
}
}
};
});

React.useEffect(() => {
const timer = setInterval(() => {
bufferRef.current();
}, 500);

return () => {
clearInterval(timer);
};
}, []);

React.useEffect(() => {
const timer = setInterval(() => {
progressRef.current();
Expand Down
24 changes: 4 additions & 20 deletions docs/data/material/components/progress/LinearBuffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ export default function LinearBuffer() {
const [progress, setProgress] = React.useState(0);
const [buffer, setBuffer] = React.useState(10);

const bufferRef = React.useRef(() => {});
React.useEffect(() => {
bufferRef.current = () => {
if (buffer < 100) {
const newBuffer = buffer + 1 + Math.random() * 10;
setBuffer(newBuffer > 100 ? 100 : newBuffer);
}
};
});

const progressRef = React.useRef(() => {});
React.useEffect(() => {
progressRef.current = () => {
Expand All @@ -24,20 +14,14 @@ export default function LinearBuffer() {
setBuffer(10);
} else {
setProgress(progress + 1);
if (buffer < 100 && progress % 5 === 0) {
const newBuffer = buffer + 1 + Math.random() * 10;
setBuffer(newBuffer > 100 ? 100 : newBuffer);
}
}
};
});

React.useEffect(() => {
const timer = setInterval(() => {
bufferRef.current();
}, 500);

return () => {
clearInterval(timer);
};
}, []);

React.useEffect(() => {
const timer = setInterval(() => {
progressRef.current();
Expand Down

0 comments on commit 330cc31

Please sign in to comment.