Skip to content

Commit

Permalink
Migrate to new countup version (#509)
Browse files Browse the repository at this point in the history
* Migrate to new countup version

* Update snapshot

* Update README.md
  • Loading branch information
mmarkelov committed Jul 7, 2021
1 parent deb2754 commit 944d721
Show file tree
Hide file tree
Showing 12 changed files with 476 additions and 1,405 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ Note that `delay={0}` will automatically start the count up.
import { useCountUp } from 'react-countup';

const SimpleHook = () => {
const { countUp } = useCountUp({ end: 1234567 });
return <div>{countUp}</div>;
useCountUp({ end: 1234567 });
return <span id="counter"/>;
};
```

Expand All @@ -164,7 +164,9 @@ const SimpleHook = () => {
import { useCountUp } from 'react-countup';

const CompleteHook = () => {
const { countUp, start, pauseResume, reset, update } = useCountUp({
const countUpRef = React.useRef(null);
const { start, pauseResume, reset, update } = useCountUp({
ref: countUpRef,
start: 0,
end: 1234567,
delay: 1000,
Expand All @@ -177,7 +179,7 @@ const CompleteHook = () => {
});
return (
<div>
<div>{countUp}</div>
<div ref={countUpRef}/>
<button onClick={start}>Start</button>
<button onClick={reset}>Reset</button>
<button onClick={pauseResume}>Pause/Resume</button>
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type EasingFn = (t: number, b: number, c: number, d: number) => number;
interface CommonProps {
decimal?: string;
decimals?: number;
delay?: number;
duration?: number;
easingFn?: EasingFn;
end: number;
Expand All @@ -58,7 +59,6 @@ interface CommonProps {

export interface CountUpProps extends CommonProps, CallbackProps {
className?: string;
delay?: number;
redraw?: boolean;
preserveValue?: boolean;
children?: (props: RenderCounterProps) => JSX.Element;
Expand All @@ -68,7 +68,6 @@ declare class CountUp extends React.Component<CountUpProps, any> {}

export interface useCountUpProps extends CommonProps, CallbackProps {
startOnMount?: boolean;
delay?: number;
}

type countUpHook = (
Expand Down
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
testEnvironment: 'jsdom',
setupFiles: ['raf/polyfill'],
testURL: 'http://localhost',
transformIgnorePatterns: [
"/node_modules/(?!countup\\.js).+\\.js$",
],
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"react": ">= 16.3.0"
},
"dependencies": {
"countup.js": "^1.9.3",
"countup.js": "^2.0.7",
"prop-types": "^15.7.2",
"warning": "^4.0.3"
},
Expand All @@ -44,7 +44,7 @@
"@babel/preset-react": "7.14.5",
"@testing-library/react": "12.0.0",
"@testing-library/react-hooks": "7.0.1",
"babel-jest": "26.6.3",
"babel-jest": "27.0.6",
"jest": "27.0.6",
"prettier": "2.3.2",
"pretty-quick": "3.1.1",
Expand Down
4 changes: 3 additions & 1 deletion src/CountUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ class CountUp extends Component {
if (this.timeoutId) {
clearTimeout(this.timeoutId);
}
this.instance.reset();
if (this.instance.target) {
this.instance.reset();
}
}

createInstance = () => {
Expand Down
Loading

0 comments on commit 944d721

Please sign in to comment.