progressbar.js icon indicating copy to clipboard operation
progressbar.js copied to clipboard

How can I use this with React?

Open bobdeei opened this issue 5 years ago • 4 comments

I've install react-progressbar.js but has no idea how it should work with React.

Can you provide me an example on how to make it work with React?

Thank you Duy

bobdeei avatar Apr 21 '19 16:04 bobdeei

Oh it seems like the React package is deprecated now. It has not been supported for 3 years.

I'm sorry about that. I should have checked the last published date first :)

bobdeei avatar Apr 21 '19 17:04 bobdeei

@bobdeei you could find some way to integrate the actual release with React? I'm working with SSR and isomorphic JS and i'm not pretty sure how to integrate.

dudesl avatar May 02 '19 18:05 dudesl

You can easily use it with react, example:

import React, { useEffect, useMemo, useCallback } from 'react';
import { Circle } from 'progressbar.js';

const wrapper = document.createElement('div');

const ProgressCircle = ({ animate }) => {
  const bar = useMemo(
    () =>
      new Circle(wrapper, {
        strokeWidth: 6,
        easing: 'easeInOut',
        duration: 1400,
        color: '#FFEA82',
        trailColor: '#eee',
        trailWidth: 1,
        svgStyle: null,
      }),
    []
  );

  const node = useCallback(node => {
    if (node) {
       node.appendChild(wrapper);
    }
  }, []);

  useEffect(() => {
    bar.animate(animate);
  }, [animate, bar]);

  return <div ref={node} />;
};

export default ProgressCircle;

And usage:

const RandomCircle = () => {
    const [animate, setAnimate] = useState(0.0);
    return (
        <div>
            <ProgressCircle animate={animate}/>
            <button onClick={() => setAnimate(Math.random())}>Animate</button>
        </div>
    );
};

arya-s avatar Jun 07 '19 05:06 arya-s

All the examples ProgressBar.js has, saying it works with React. Spent 2 hours with no luck. Took all of 30 seconds with the help of @arya-s . Thank you!

cybersmithio avatar Dec 01 '22 20:12 cybersmithio