Gathering detailed insights and metrics for transition-hook
Gathering detailed insights and metrics for transition-hook
Gathering detailed insights and metrics for transition-hook
Gathering detailed insights and metrics for transition-hook
@vanyapr/transition-hook
☄️ An extremely light-weight react transition animation hook which is simpler and easier to use than react-transition-group
react-transition-state
Zero dependency React transition state machine.
react-transition-group
A react component toolset for managing animations
d3-transition
Animated transitions for D3 selections.
☄️ An extremely light-weight react transition animation hook which is simpler and easier to use than react-transition-group
npm install transition-hook
77.6
Supply Chain
94.6
Quality
75.6
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
374 Stars
78 Commits
17 Forks
3 Watching
3 Branches
3 Contributors
Updated on 19 Nov 2024
Minified
Minified + Gzipped
TypeScript (85.31%)
JavaScript (13.87%)
Shell (0.81%)
Cumulative downloads
Total Downloads
Last day
-36.5%
953
Compared to previous day
Last week
-13.5%
7,224
Compared to previous week
Last month
13.9%
33,950
Compared to previous month
Last year
-16.8%
429,506
Compared to previous year
19
An extremely light-weight(1kb) react transition animation hook which is simpler and easier to use than react-transition-group
See Example |
See Example in Codesandbox
See More Examples in Codesandbox
Install with yarn
1yarn add transition-hook
Or install with npm
1npm install transition-hook --save
This hook transforms a boolean state into transition stage('from' | 'enter' | 'leave'), and unmount the component after timeout.
1const [onOff, setOnOff] = useState(true) 2const {stage, shouldMount} = useTransition(onOff, 300) // (state, timeout) 3 4return <div> 5 <button onClick={()=>setOnOff(!onOff)}>toggle</button> 6 {shouldMount && ( 7 <p style={{ 8 transition: '.3s', 9 opacity: stage === 'enter' ? 1 : 0 10 }}> 11 Hey guys, I'm fading 12 </p> 13 )} 14</div>
This hook transforms when the state changes.
1const [count, setCount] = useState(0) 2const transition = useSwitchTransition(count, 300, 'default') // (state, timeout, mode) 3 4return <div> 5 <button onClick={()=>setCount(count+1)}>add</button> 6 {transition((state, stage)=>( 7 <p style={{ 8 transition: '.3s', 9 opacity: stage === 'enter' ? 1 : 0, 10 transform: { 11 from: 'translateX(-100%)', 12 enter: 'translateX(0%)', 13 leave: 'translateX(100%)', 14 }[stage] 15 }}>{state}</p> 16 ))} 17</div>
If you prefer FaCC pattern usage, there it is!
1const [onOff, setOnOff] = useState(true) 2 3return <div> 4 <button onClick={()=>setOnOff(!onOff)}>toggle</button> 5 <Transition state={onOff} timeout={300}> 6 {(stage, shouldMount)=>shouldMount &&( 7 <p style={{ 8 transition: '.3s', 9 opacity: stage === 'enter' ? 1 : 0 10 }}> 11 Hey guys, I'm fading 12 </p> 13 )} 14 </Transition> 15</div>
FaCC pattern version of useSwitchTransition
1 <SwitchTransition state={count} timeout={300} mode='default'> 2 {(state, stage) => ( 3 <h1 4 style={{ 5 transition: '.3s', 6 opacity: stage === 'enter' ? 1 : 0, 7 transform: { 8 from: 'translateX(-100%) scale(1.2)', 9 enter: 'translateX(0)', 10 leave: 'translateX(100%) scale(0)' 11 }[stage] 12 }}> 13 {state} {stage} hello 14 </h1> 15 )} 16 </SwitchTransition>
1 const {stage, shouldMount} = useTransition(onOff, 300)
Parameters | Type | Description |
---|---|---|
state | boolean | Required. Your boolean state, which controls animation in and out |
timeout | number | Required. How long before the animation ends and unmounts |
Returns | Type | Description |
---|---|---|
stage | Stage: from | enter | leave | Use three different stage to perform your animation |
shouldMount | boolean | Whether the component should be mounted |
1 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 | in-out | Optional. Default to default mode |
1 <Transition state={onOff} timeout={300}> 2 {(stage, shouldMount) => shouldMount && <div style={{...}}>hello</div>} 3 </Transition>
Props | Type | Description |
---|---|---|
state | boolean | Required. Your boolean state, which controls animation in and out |
timeout | number | Required. How long before the animation ends and unmounts |
children | (stage: Stage, shouldMount: boolean)=>React.ReactNode | Required. FaCC pattern. |
1 <SwitchTransition state={count} timeout={300}> 2 {(state, stage) => <div style={{...}}>{state} hello</div>} 3 </SwitchTransition>
Props | Type | Description |
---|---|---|
state | any | Required. Your boolean state, which controls animation in and out |
timeout | number | Required. How long before the animation ends and unmounts |
mode | default | out-in | in-out | Optional. Default to default mode |
children | (state: any, stage: Stage)=>React.ReactNode | Required. FaCC pattern. |
1 <ListTransition list={list} timeout={300}> 2 {(item, stage)=><h1 style={...}>{item}</h1>} 3 </ListTransition>
Props | Type | Description |
---|---|---|
list | Array<any> | Required. Your array state |
timeout | number | Required. How long before the animation ends and unmounts |
children | (item: any, stage: Stage)=>React.ReactNode | Required. FaCC pattern. |
Repo | Intro |
---|---|
🧻 infinite-scroll-hook | Scroll down to load more never been so easy! |
☄️ transition-hook | An extremely light-weight react transition animation hook |
No vulnerabilities found.
No security vulnerabilities found.