-
Notifications
You must be signed in to change notification settings - Fork 558
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
Suggestion for using forwardRef for imperative API (QUESTION) #56
Comments
You could set up your |
@j-f1 First of all, thanks for the response. But than it wouldn't be straight forward to use in cases when |
If you need the |
I would like to add an example to be sure i'm not missing something here.
Given this component:
We could use it with a simple API: But now with out
The consumer will use it this way:
Of course this is limiting as the consumer can't "just" render anything. for example text is out of the question, but more important the consumer will need to pass the ref down to I don't mind this change as i understand this is a minor downgrade compare to the benefits we gain with ditching |
I'm not sure it's the right place but it's not a bug so I'm not sure where is the right place. (Maybe a new API)
In project I work on, there is a
TextField
component which is more than a wrapper for<input>
. It wraps the<input>
element with a<div>
to overcome some limitation that needed by a requested design.TL;DR
The forwardRef API as is seems to not be usable for this use case, because:
The actual wrapper is a
<div>
which is not what you expect when you manually want the textfield element. Because you would expect the<input>
for using commands such as#focus()
or#checkValidity()
and soBut sometimes you do need the
<div>
container because you need to measure the element which the inner<input>
is useless for.ReactDOM.findDOMNode
from what I've search isn't recommended. But it also blocks the ability to use the code in React Native or other renderersToday, I add functions to the component class such as
TextField#focus()
(that calls focus on the<input>
) and I'll probably need to add one forTextField#getClientRects()
(for measure the<div>
). But, it seams redundant and not very stable as more native DOM functionality is needed to warped by the component class for imperative needs use cases (as the project grows and more needs are added).What do you think I should do?
Maybe forwardRef need some tweaks?
Maybe a new API is needed?
Or maybe the current scenario of what I do is the least worst option?
The text was updated successfully, but these errors were encountered: