Skip to content

Instantly share code, notes, and snippets.

@crazypixel
Created September 8, 2019 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazypixel/229258fcdc12b9da467235c5ba0a3418 to your computer and use it in GitHub Desktop.
Save crazypixel/229258fcdc12b9da467235c5ba0a3418 to your computer and use it in GitHub Desktop.
use memo for styles
const styles = useMemo(() => ({
cursor: state.isDragging ? '-webkit-grabbing' : '-webkit-grab',
transform: `translate(${state.translation.x}px, ${state.translation.y}px)`,
transition: state.isDragging ? 'none' : 'transform 500ms',
zIndex: state.isDragging ? 2 : 1,
position: state.isDragging ? 'absolute' : 'relative'
}), [state.isDragging, state.translation]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment