3.0.8 • Published 2 months ago

lesca-use-tween v3.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
2 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.0.8

2 months ago

3.0.7

2 months ago

3.0.6

6 months ago

3.0.5

6 months ago

3.0.4

7 months ago

3.0.3

7 months ago

3.0.2

7 months ago

2.6.0

11 months ago

3.0.1

11 months ago

2.5.6

11 months ago

2.5.5

12 months ago

3.0.0

11 months ago

2.5.2

12 months ago

2.5.4

12 months ago

2.5.0

1 year ago

2.5.1

1 year ago

2.4.3

1 year ago

2.4.5

1 year ago

2.4.4

1 year ago

2.4.7

1 year ago

2.4.6

1 year ago

2.4.9

1 year ago

2.4.8

1 year ago

2.3.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.3.1

1 year ago

2.4.2

1 year ago

2.1.0

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.3.4

2 years ago

1.2.5

2 years ago

1.3.3

2 years ago

1.2.4

2 years ago

1.1.5

2 years ago

1.3.2

2 years ago

1.2.3

2 years ago

1.1.4

2 years ago

1.3.1

2 years ago

1.2.2

2 years ago

1.1.3

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.2

2 years ago

1.2.9

2 years ago

1.2.10

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago