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

I got an error when I use flipTo function in a 'react' project #25

Open
Jickey opened this issue Dec 22, 2021 · 8 comments
Open

I got an error when I use flipTo function in a 'react' project #25

Jickey opened this issue Dec 22, 2021 · 8 comments

Comments

@Jickey
Copy link

Jickey commented Dec 22, 2021

my react component code:

const FlipNumber = ({ number: realNumber, className }) => {
  const ref = useRef();
  const flipRef = useRef(null);
  useEffect(() => {
    if (!flipRef.current) {
      flipRef.current = new Flip({
       node: ref.current,
        from: 0,
        to: realNumber,
        duration: 1.5,
        separator: ',',
      });
    } else {
      // error when flipTo runs 
      flipRef.current.flipTo({ to: realNumber });
    }
  }, [realNumber]);
  return (
   <div
      ref={ref}
    />
  );
};

image

image

@gaoryrt
Copy link
Owner

gaoryrt commented Dec 23, 2021

I think this will work:
https://codesandbox.io/s/snowy-tdd-gf9hp?file=/src/App.js:89-488

const FlipNumber = ({ number: realNumber }) => {
  const ref = useRef();
  const flipRef = useRef(null);
  useEffect(() => {
    flipRef.current = new Flip({
      node: ref.current,
      from: 0,
      to: realNumber,
      duration: 1.5,
      separator: ","
    });
  }, []);
  useEffect(() => {
    flipRef.current.flipTo({ to: realNumber });
  }, [realNumber]);

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

@Jickey
Copy link
Author

Jickey commented Dec 24, 2021

Yeah. It does work in my 'vite' demo project but I failed in my production project, which meas it may be an incompatibility problem. Forget it. Thanks very much for your reply !

@xmsz
Copy link

xmsz commented Dec 6, 2022

any updated?

@gaoryrt
Copy link
Owner

gaoryrt commented Dec 7, 2022

@xmsz I believe this works effectively

@xmsz
Copy link

xmsz commented Dec 7, 2022

@xmsz I believe this works effectively

image

@edgar-505
Copy link

@gaoryrt still error...

@gaoryrt
Copy link
Owner

gaoryrt commented Nov 20, 2023

@gaoryrt still error...
Please provide a minimal reproduction.

@TanYiBing
Copy link

似乎是数字位数不一样,所以提示 Cannot read properties of undefined (reading 'childNodes')

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

No branches or pull requests

5 participants