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

Add Ref to Grid #1176

Merged
merged 1 commit into from
Apr 29, 2020
Merged

Add Ref to Grid #1176

merged 1 commit into from
Apr 29, 2020

Conversation

paul-sachs
Copy link
Contributor

Add reference prop so we can get the internal div element. Useful for measurement and scroll control.

We could use React.forwardRef but that does a few things:

  • limits version of compatible react
  • breaking API change (ref would now be the div, vs the class object)

@github-actions github-actions bot added the documentation use this label for changes in documentation label Mar 22, 2020
@github-actions
Copy link

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this PR will be closed in 7 days

@github-actions github-actions bot added the stale The label to apply when a pull request or an issue is stale label Apr 22, 2020
@STRML
Copy link
Collaborator

STRML commented Apr 29, 2020

That's pretty useful, especially since ReactDOM.findDOMNode() is discouraged now.

It looks like this is pretty unsurprising / used elsewhere (https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/guides/using-inner-ref.md), so I'll merge.

@STRML STRML merged commit 83251e5 into react-grid-layout:master Apr 29, 2020
@STRML
Copy link
Collaborator

STRML commented Apr 29, 2020

Thanks for the contribution!

@ben-elsen
Copy link

@paul-sachs Could you provide an example of how to implement this because I tried but I keep getting the error:

Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of DraggableCore which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://fb.me/react-strict-mode-find-node

@paul-sachs paul-sachs deleted the add-ref branch September 10, 2020 15:38
@paul-sachs
Copy link
Contributor Author

@ben-elsen not sure what you mean by implement. To use the new prop:

const ref = useRef();
return (
  <GridLayout innerRef={ref} />
);

This change didn't remove any references to findDOMNode within the source. More work would need to be done to remove the usage of findDOMNode.

@ben-elsen
Copy link

@paul-sachs I misunderstood this feature.. I thought it was intended to fix the warning. Sorry :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation use this label for changes in documentation stale The label to apply when a pull request or an issue is stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants