Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a mock element instead of -1 #192

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/useCountUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import CountUp from './CountUp';
import { createCountUpInstance } from './common';

// CountUp.js requires an element to execute it's animation,
// since it only checks for truthy values -1 is enough to mock an element.
const NO_ELEMENT = -1;
// and just sets the innerHTML of the element.
const MOCK_ELEMENT = { innerHTML: null };

const useCountUp = props => {
const _props = { ...CountUp.defaultProps, ...props };
Expand All @@ -15,7 +15,7 @@ const useCountUp = props => {
const countUpRef = useRef(null);

const createInstance = () => {
const countUp = createCountUpInstance(NO_ELEMENT, _props);
const countUp = createCountUpInstance(MOCK_ELEMENT, _props);
let formattingFnRef = countUp.options.formattingFn;
countUp.options.formattingFn = (...args) => {
const result = formattingFnRef(...args);
Expand Down