-
-
Notifications
You must be signed in to change notification settings - Fork 732
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
Stateless function as component prop triggers a warning #748
Comments
Hey thanks for reporting this! The problem with stateless function is that we can't know how to focus the input field (reason we use a This won't give any error from the |
Hey @gpbl was this fixed in |
I'm also seeing the warning in Why not use It's not manipulating the DOM, just selecting a field that has the exact same name as you're passing to the document
.querySelector('[name="someFieldName"]')
.focus() Or is there some way I could just do this myself so long as the warning goes away? |
This can be a solution, but it is not easy as it seems – since it is possible to change the component of the input element, we really don't know what's inside there, which A solution could be using get input() {
return React.findDOMNode(this).querySelector('input')
} which will cover the most of the cases (but not the ones with multiple input fields in it). IMHO the best solution would be to use the render props pattern by passing a |
You're right! That's significantly better. My reason for not wanting any use of |
Yeah that's legit! Thanks for the suggestion @Sawtaytoes. I think however I'll change this behavior in the next major release, which will not require much refactoring from you... but it will protect others from breaking changes I can't see now using |
Hey, I have the same issue! Any chance I could make this warning go away from my side, without editing the library? |
@egloo8 the workaround suggested by @elamperti works great for me; create a component class for your input and pass that one as the component prop on DayPickerInput. |
I'm having trouble with the suggested solution since I need to pass a prop to that component:
If I try to define the component from the outsite I can do something like this:
the only way to make it work is to somehow create a class component inside the This can be done with redux easily probably, but unfortunately I can't use redux in this specific scenario. Does someone has an idea how to solve this ? |
Just wanted to clarify if this issue conflicts with the documentation as well. Getting same error: http://react-day-picker.js.org/api/DayPickerInput/#component |
This code works fine without any warnings:
|
Stumbled across this today whilst looking for a solution to the same problem. Following the guide in the docs and passing the props to the Both @elamperti and @mrbinwin 's solutions worked for me. In my case however, I was using a Styled Component as the input for the In order to add these extra props, I used the |
Hi @matthewmcclatchie,
|
CodeSandbox demo: https://codesandbox.io/s/zqx94zxy0l
Following the example in the documentation, adding a
component
property raises an error in the console saying:I've noticed that @gengue had the same issue as well some months ago (Gitter message about it)
Transforming the component passed to the picker to a class seems to fix this problem (see this other example) although it doesn't look good and it's different from what the documentation suggests.
Could you provide a better solution or update the documentation to reflect this? Thanks in advance! :)
The text was updated successfully, but these errors were encountered: