3.1.2 • Published 8 months ago

lesca-use-tween v3.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

React React React React React NPM React NPM

Why use it?

A style tweener for react hook.

Live Demo

codesandbox

Installation

npm install lesca-use-tween --save

Usage

use hook

import useTween from 'lesca-use-tween';

const Component = () => {
  const [style, setStyle, destroy] = useTween({ opacity: 0 });

  useEffect(() => {
    setStyle({ opacity: 1 }); // tween opacity 0 => 1
    return () => destroy();
  }, []);

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

use provider

prevent render on each frame. we can use provider component.

import { TweenProvider } from 'lesca-use-tween';

const Component = () => {
  // ! will not keep render each frame in this component.
  return (
    <TweenProvider
      initStyle={{ opacity: 0 }}
      tweenStyle={{ opacity: 1 }}
      tweenOptions={{ duration: 1000 }}
    >
      <div>component</div>
    </TweenProvider>
  );
};

Development

Methods

methodoptionsdescriptionreturn
useTween(initStyle:object)initStyleReact css-inline-jsstyle, setStyle, destroy
React css-inline-js

color, backgroundColor, borderColor... About color properties use hex(#FF6600) only. Transform need to split to {scale, rotate, x, y };

const style = { transform: 'scale(2) rotate(90deg) translateX(10px) translateY(20px)' } => { scale:2, rotate:90, x:10, y:20 }

Hook State Method

methodoptionsdescription
setStyle( style:object, setting:object )optionssame as useState

Options

Optionstypedescription
styleobjectReact css-inline-js
settingobjectSetting

Setting

settingtypedescriptiondefault
easingarraycss BezierBezier.OutQuart
durationnumbertween duration1000
delaynumberdelay duration0
onStartfunctioncall when tween start
onUpdatefunctioncall for each frame
onEndfunctioncall for tween finished

Features

  • maintain if necessary
3.1.2

8 months ago

3.1.1

8 months ago

3.1.0

8 months ago

3.0.8

1 year ago

3.0.7

1 year ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

2.6.0

2 years ago

3.0.1

2 years ago

2.5.6

2 years ago

2.5.5

2 years ago

3.0.0

2 years ago

2.5.2

2 years ago

2.5.4

2 years ago

2.5.0

2 years ago

2.5.1

2 years ago

2.4.3

2 years ago

2.4.5

2 years ago

2.4.4

2 years ago

2.4.7

2 years ago

2.4.6

2 years ago

2.4.9

2 years ago

2.4.8

2 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.1

3 years ago

2.4.2

2 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

4 years ago

1.3.4

3 years ago

1.2.5

4 years ago

1.3.3

3 years ago

1.2.4

4 years ago

1.1.5

4 years ago

1.3.2

3 years ago

1.2.3

4 years ago

1.1.4

4 years ago

1.3.1

3 years ago

1.2.2

4 years ago

1.1.3

4 years ago

1.3.0

3 years ago

1.2.1

4 years ago

1.1.2

4 years ago

1.2.9

3 years ago

1.2.10

3 years ago

0.0.2

4 years ago

0.0.1

4 years ago