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

Use React 16's forwardRef for most/all components #1082

Open
seansfkelley opened this issue Jun 18, 2018 · 10 comments · Fixed by #1105
Open

Use React 16's forwardRef for most/all components #1082

seansfkelley opened this issue Jun 18, 2018 · 10 comments · Fixed by #1105

Comments

@seansfkelley
Copy link
Contributor

reactstrap is a perfect use-case for React 16's new forwardRef API. Since most components in this library have predictable and well-defined DOM they produce, it would be very useful to have them forward their refs along to the underlying elements so consumers like myself don't have to wrap access in ReactDOM.findDOMNode when we want to e.g. implement a scroll-related feature.

@TheSharpieOne
Copy link
Member

I'm all for this, but it will be a breaking change since it will change the require version of react needed as a peerDep.

@illiteratewriter
Copy link
Member

If adding refs is all that is needed, we can do that like how we did https://github.com/reactstrap/reactstrap/issues/1054, so that we don't have to change react version, right? So wouldn't it be better to do it like that so we don't have to bumb the version up?

@seansfkelley
Copy link
Contributor Author

seansfkelley commented Jun 22, 2018

True. You could put innerRef on everything, and use this issue as a tracking issue for the eventual deprecation and replacement with forwardRef as noted in #1054 (comment).

@seansfkelley
Copy link
Contributor Author

@TheSharpieOne when would you accept a PR for this breaking change? I keep coming up against this cause I want to attach refs to things that often turn out to be stateless components. I'd be open to making a PR to apply the change as well. We might be able to keep innerRef around as a deprecated alias to preserve API-compatibility even as the minimum React version is raised.

It's a shame that 16.3 was introduced not 6 days after #916 dropped support for versions below 16. :(

@TheSharpieOne
Copy link
Member

TheSharpieOne commented Oct 31, 2018

@seansfkelley there is a v7 branch, make PRs with breaking changes to that branch, eventually it will be merged and released.

@seansfkelley
Copy link
Contributor Author

@TheSharpieOne looks like I just missed the chance to get into v7, but I just opened #1356 for the nest release.

@iamandrewluca
Copy link
Contributor

When you start using forwardRef in a component library, you should treat it as a breaking change and release a new major version of your library. This is because your library likely has an observably different behavior (such as what refs get assigned to, and what types are exported), and this can break apps and other libraries that depend on the old behavior.
https://reactjs.org/docs/forwarding-refs.html#note-for-component-library-maintainers

@TheSharpieOne
Copy link
Member

Yes, it would be nice to get forwardRef into the next major release. This missed v7 as well as v8

@iamandrewluca
Copy link
Contributor

@TheSharpieOne Now I'm working on reactjs/react-transition-group#559 to migrate from deprecated findDOMNode then I think I'll create a new PR from #1356, to migrate to forward ref, and use new react-transition-group api, so we can finally use React.StrictMode in our app.

@darron1217
Copy link

Any updates on this issue?
It is really needed.

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

Successfully merging a pull request may close this issue.

5 participants