0.1.16 • Published 7 years ago
@render-props/will-change v0.1.16
WillChange
A state container which provides an interface for applying CSS will-change
styles to its child components when given events fire. This is incredibly useful
because browsers recommend that you use this CSS property sparingly, as it's
a GPU-hog. You should really only be applying it directly before the event
occurs.
Installation
yarn add @render-props/will-change or npm i @render-props/will-change
Usage
import WillChange from '@render-props/will-change'
const WillChangeButton = props => (
<WillChange properties={['padding', 'font-size']} onHover>
{({
willChangeRef,
willChange,
style
}) => (
<button
ref={willChangeRef}
style={
{
...style,
transition: 'padding 0.16s ease-out, font-size 0.16s ease-out'
}
}
>
Hover me
</button>
)}
</WillChange>
)Props
properties {array}- array of CSS properties that
will-changewhen the event occurs
- array of CSS properties that
all {bool}- if
true,allwill be the value of thewill-changeproperty
- if
eventTypes {array}- names of events to listen for. When these events fire,
will-changewill be applied to the style object
- names of events to listen for. When these events fire,
onTouchStart {bool}- makes the component listen to the
ontouchstartevent
- makes the component listen to the
onTouchEnd {bool}- makes the component listen to the
touchendevent
- makes the component listen to the
onTouchMove {bool}- makes the component listen to the
touchmoveevent
- makes the component listen to the
onMouseMove {bool}- makes the component listen to the
mousemoveevent
- makes the component listen to the
onClick {bool}- makes the component listen to the
mousedownevent
- makes the component listen to the
onHover {bool}- makes the component listen to the
mouseenterevent
- makes the component listen to the
onMouseEnter {bool}- makes the component listen to the
mouseenterevent
- makes the component listen to the
onMouseLeave {bool}- makes the component listen to the
mouseleaveevent
- makes the component listen to the
onScroll {bool}- makes the component listen to the
scrollevent
- makes the component listen to the
onResize {bool}- makes the component listen to the
resizeevent
- makes the component listen to the
onFocus {bool}- makes the component listen to the
focusevent
- makes the component listen to the
onBlur {bool}- makes the component listen to the
blurevent
- makes the component listen to the
onDrag {bool}- makes the component listen to the
dragstartevent
- makes the component listen to the
onDrop {bool}- makes the component listen to the
dropevent
- makes the component listen to the
staleTimeout {milliseconds}- after this amount a time
will-changewill be removed from the style property. Defaults to1000, 1-second.
- after this amount a time
Render Props
Ref
willChangeRef- This
refmust be provided to whatever element you are trying to observe the the events of. e.g.<div ref={willChangeRef}>
- This
Methods
willChange()- turns on the
will-changestyle property, regardless of prop-defined events firing<WillChange properties={['background-color']}> {({willChange}) => <div onClick={willChange}/>} </WillChange>
- turns on the
State
style {object}- the style object with or without the
will-changeproperty depending on if it is turned on
- the style object with or without the