Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass props to DragLayer #979

Merged
merged 2 commits into from Mar 21, 2018
Merged

Pass props to DragLayer #979

merged 2 commits into from Mar 21, 2018

Conversation

casr
Copy link
Contributor

@casr casr commented Feb 26, 2018

I have found this useful for when the mouse x/y are too granular and therefore update the component much more frequently than required.

Example:

render() {
  return (
    <CustomDragLayer gridWidth={3} gridHeight={3} />
  )
}
const collect = (monitor, props) => {
  const clientOffset = monitor.getClientOffset()
  const { gridWidth, gridHeight } = props

  if (clientOffset != null) {
    return {
      gridX: Math.floor(clientOffset.x / gridWidth),
      gridY: Math.floor(clientOffset.y / gridHeight)
    }
  }

  return { gridX: null, gridY: null }
};
DragLayer(collect)(CustomDragLayer);

@darthtrevino
Copy link
Member

@casr Interesting, I like the idea! Can you write up an example of using custom drag layer props? In your example here I don't see the new props argument being used at all.

@casr
Copy link
Contributor Author

casr commented Mar 9, 2018

Ah, I missed off a crucial line:

const { gridWidth, gridHeight } = props

I will amend the example above to reflect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants