Skip to content

Commit

Permalink
bug: react hooks setInterval and clearInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
irohitb committed Apr 7, 2021
1 parent bb34ae8 commit 109e94d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ const SafeAreaViewDeciderDefaultProps = {
const ProgressBar = ({ currentProgress, colorOfNonProgressBar = 'white', colorOfProgressBar = 'black', heightOfProgressBar = 5, SafeAreaViewDeciderProps = SafeAreaViewDeciderDefaultProps, totalNumberOfProgressBars, blink = true, durationForTheBlink = 500, hideProgressBar = false, }) => {
const width = Dimensions.get('window').width;
const [blinkVisibility, setBlinkVisiblity] = React.useState(false);
const blinkInterval = React.useRef(null);
const progressBarArray = [];
const changeComponentBlinkVisibility = () => {
setBlinkVisiblity(!blinkVisibility);
};
React.useEffect(() => {
if (blink) {
setInterval(() => {
changeComponentBlinkVisibility();
const timer = setInterval(() => {
console.log('called');
setBlinkVisiblity((blinkVisibility) => !blinkVisibility);
}, durationForTheBlink);
return () => {
clearInterval(timer);
};
}
}, []);
if (hideProgressBar) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-form-progress",
"version": "1.0.19",
"version": "1.0.20",
"description": "A react native component super useful in displaying progress when user is filling up forms like signup page, setting, information catering etc",
"main": "lib/index.js",
"types": "lib",
Expand Down
13 changes: 7 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ const ProgressBar = ({
}: ProgressBarProps) => {
const width = Dimensions.get('window').width;
const [blinkVisibility, setBlinkVisiblity] = React.useState(false);
const blinkInterval: any = React.useRef(null);
const progressBarArray = [];

const changeComponentBlinkVisibility = () => {
setBlinkVisiblity(!blinkVisibility);
};

React.useEffect(() => {
if (blink) {
setInterval(() => {
changeComponentBlinkVisibility();
const timer = setInterval(() => {
console.log('called');
setBlinkVisiblity((blinkVisibility) => !blinkVisibility);
}, durationForTheBlink);
return () => {
clearInterval(timer);
};
}
}, []);

Expand Down

0 comments on commit 109e94d

Please sign in to comment.