@igorriti/react-fluid-animation
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Installation

npm install @igorriti/react-fluid-animation

or

yarn add @igorriti/react-fluid-animation

Usage

import ReactFluidAnimation from '@igorriti/react-fluid-animation';

export default function App() {
  return (
    <ReactFluidAnimation />
  );
}

Usage with server-side rendering

This package works only on client side because it depdends on WebGL technology.

We need to load package dynamically after the hydration process is complete.

Let's see how this can be done:

const DynamicAnimation = dynamic(() => import('@igorriti/react-fluid-animation'));

export default function App() {
  const [isAfterHydration, setIsAfterHydration] = useState<boolean>(false);
  
  useEffect(() => {
    if (!isAfterHydration) setIsAfterHydration(true);
  }, [isAfterHydration, setIsAfterHydration]);

  return isAfterHydration ? <DynamicAnimation /> : null;
}

This workaround give us the opportunity to dynamically load the component and mount it right after hydration is complete to get around hydration errors from React.

Props & types

Props of the ReactFluidAnimation component:

export interface Props {
  config?: IAnimationConfig; // animation config
  style?: object; // styles object passed to container <div>
  animationRef?: (animation: Animation) => void, // function to capture animation object
}

Animation config

export interface IAnimationConfig {
  textureDownsample: number;
  densityDissipation: number;
  velocityDissipation: number;
  pressureDissipation: number;
  pressureIterations: number;
  curl: number;
  splatRadius: number;
}

Animation object

export class Animation {
  config: IAnimationConfig; // current config of the animation
  width: number; // width of the canvas
  height: number; // height of the canvas
  addRandomSplats(count: number): void; // function to apply random splats on screen
}

Package Sidebar

Install

npm i @igorriti/react-fluid-animation

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

217 kB

Total Files

26

Last publish

Collaborators

  • igorriti