diff --git a/README.md b/README.md index 14a4e54..3e135de 100644 --- a/README.md +++ b/README.md @@ -16,20 +16,41 @@

- example + example
See Example | See Example in Codesandbox

+

+ + example + + + example + +

+

+ + example + + + example + +

+

+ See More Examples in Codesandbox +


- [Installation](#installation) - [Usage](#usage) - [useTransition](#usetransition) + - [useSwitchTransition](#useswitchtransition) - [Transition](#transition) - [API Reference](#api-reference) - [useTransition(state, timeout)](#usetransitionstate-timeout) + - [useSwitchTransition(state, timeout, mode)](#useswitchtransitionstate-timeout-mode) - [Transition](#transition-1) - [License](#license) @@ -51,7 +72,7 @@ npm install transition-hook --save ### useTransition -This hook transform a boolean state into transition stage('from' | 'enter' | 'leave'), and unmount the component after timeout. +This hook transforms a boolean state into transition stage('from' | 'enter' | 'leave'), and unmount the component after timeout. ```jsx const [onOff, setOnOff] = useState(true) @@ -70,6 +91,30 @@ return
``` +### useSwitchTransition + +This hook transforms when the state changes. + +```jsx +const [count, setCount] = useState(0) +const transition = useSwitchTransition(count, 300, 'default') // (state, timeout, mode) + +return
+ + {transition((state, stage)=>( +

{state}

+ ))} +
+``` + ### Transition If you prefer FaCC pattern usage, there it is! @@ -112,6 +157,18 @@ return
| `stage` | Stage: `from` \| `enter` \| `leave` | Use three different stage to perform your animation | | `shouldMount` | `boolean` | Whether the component should be mounted | +### useSwitchTransition(state, timeout, mode) + +```js + const transition = useSwitchTransition(onOff, 300, default) +``` + +| Parameters | Type | Description | +| :--------- | :--------------------------------- | :------------------------------------------------------------ | +| `state` | `any` | **Required**. Your state, which triggers animation | +| `timeout` | `number` | **Required**. How long before the animation ends and unmounts | +| `mode` | `default` \| `out-in` \| `int-out` | **Optional**. Default to `default` mode | + ### Transition ```jsx diff --git a/gifs/basic-switch-transition.gif b/gifs/basic-switch-transition.gif new file mode 100644 index 0000000..54915ba Binary files /dev/null and b/gifs/basic-switch-transition.gif differ diff --git a/gifs/basic.gif b/gifs/basic.gif new file mode 100644 index 0000000..9c8c676 Binary files /dev/null and b/gifs/basic.gif differ diff --git a/gifs/emoji-switch-transition.gif b/gifs/emoji-switch-transition.gif new file mode 100644 index 0000000..cb63253 Binary files /dev/null and b/gifs/emoji-switch-transition.gif differ diff --git a/gifs/emoji-transition.gif b/gifs/emoji-transition.gif new file mode 100644 index 0000000..53c52dc Binary files /dev/null and b/gifs/emoji-transition.gif differ diff --git a/gifs/transition-with-key.gif b/gifs/transition-with-key.gif new file mode 100644 index 0000000..285c7ef Binary files /dev/null and b/gifs/transition-with-key.gif differ