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

Hookify react-countup #515

Merged
merged 27 commits into from
Aug 14, 2021
Merged

Hookify react-countup #515

merged 27 commits into from
Aug 14, 2021

Conversation

johnrom
Copy link
Contributor

@johnrom johnrom commented Jul 23, 2021

This reimplements react-countup as a hook first, with a lightweight component wrapper. It cuts the codebase in almost half.

This PR is based off of #514. so that should be merged first. There should be no breaking changes, but I'd still recommend both PRs use a major version bump.

johnrom and others added 22 commits July 22, 2021 12:00
… -- the component initialized immediately and set "0" as the value, and the hook delayed initialization and returned "" as the value. This breaks backwards compatibility by setting both to "0", though it may need to be re-thought.
# Conflicts:
#	src/CountUp.tsx
#	src/useCountUp.ts
…JS.Timeout in node, or number in the browser.
@johnrom
Copy link
Contributor Author

johnrom commented Jul 26, 2021

Updated with changes from #514

These changes can be tested here:

https://www.npmjs.com/package/@johnrom/react-countup/v/5.0.0-johnrom2

# Conflicts:
#	babel.config.json
#	src/CountUp.tsx
#	src/common.ts
#	src/useCountUp.ts
@mmarkelov
Copy link
Collaborator

@johnrom i'm okay with this PR. Could you please resolve conflicts?

@johnrom
Copy link
Contributor Author

johnrom commented Aug 6, 2021

I'll try and take a look next week.

# Conflicts:
#	package.json
#	src/CountUp.tsx
#	src/common.ts
#	src/useCountUp.ts
@johnrom
Copy link
Contributor Author

johnrom commented Aug 12, 2021

@mmarkelov your changes since I made this PR were pretty much the opposite of mine. however, I think I was able to resolve all of the conflicts successfully.

};

const useCountUp = (props: useCountUpProps) => {
const parsedProps = { ...defaults, ...props };
const { ref } = parsedProps;
const config = useMemo(() => ({ ...DEFAULTS, ...props }), [props]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can use destructuring here:

const { ref, startOnMount, enableReinitialize, delay, onStart, onEnd, onPauseResume, onReset, onUpdate, ...countUpProps } = useMemo(() => ({ ...DEFAULTS, ...props }), [props]);

...
  const createInstance = useEventCallback(() => {
    return createCountUpInstance(
      typeof ref === 'string' ? ref : ref.current,
      countUpProps
    )
  });

@mmarkelov
Copy link
Collaborator

@johnrom, thanks a lot for your work! i just left one comment to fix and we will ready to merge it.

@johnrom
Copy link
Contributor Author

johnrom commented Aug 13, 2021

I have made the requested change. I also noticed some rules of hooks errors and opened a new PR initializing eslint, and fixing all eslint issues using standard eslint + prettier practices.

@mmarkelov mmarkelov merged commit 8fbbaa6 into glennreyes:master Aug 14, 2021
@johnrom johnrom deleted the johnrom/hookify branch August 27, 2021 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants