'How I use React Spring Number Animation? when i run this code catch a error

You can see my code is here:

import React, { useState } from 'react';
import { config, useSpring, animated } from 'react-spring';
const TotalCounter = () => {
    const [flip, set] = useState(false)
    const { number } = useSpring({
        reset: true,
        reverse: flip,
        from: { number: 0 },
        number: 1,
        delay: 200,
        config: config.molasses,
        onRest: () => set(!flip),
    })
    return (
           <animated.div>{number.to(n => n.toFixed(2))}</animated.div>
    );
};

export default TotalCounter;

This is the Error:

This is the error I got

Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app

The above error occurred in the < TotalCounter > component



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source