Stateless customInput?
See original GitHub issueI’m trying to pass my existing Input to <DatePicker />
but it happens to be a stateless component. This seems to create two errors for me.
One is this
warning.js:36Warning: Stateless function components cannot be given refs (See ref "input" in Input created by t). Attempts to access this ref will fail.
The other is this, which seems related to #694
Uncaught TypeError: Cannot read property 'focus' of null
at t.n.setFocus (react-datepicker.min.js:1)
at react-datepicker.min.js:1
I’m not sure how best to proceed. Has anyone else encountered this scenario?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:31
- Comments:17
Top Results From Across the Web
How can I get an input's value on a button click in a Stateless ...
Your CustomInput component: import React from "react"; import PropTypes from "prop- ...
Read more >Stateless Model Evaluation - Vespa Documentation
Stateless Model Evaluation ... Vespa's speciality is evaluating machine-learned models quickly over large numbers of data points. However, it can also be used...
Read more >Passing data into Angular components with @Input
This custom input binding is created via the @Input() decorator! ... Taking a stateless counter component, we need to tell Angular that we'd ......
Read more >How can I get an input's value on a button click in a Stateless ...
This approach allows your component to remain stateless and also doesn't require ... import PropTypes from "prop-types"; class CustomInput extends React.
Read more >Custom input transformation — IPython 1.2.1
Custom input transformation. String based transformations. Stateless transformations; Coroutine transformers; Token-based transformers.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Building on @mfalade and @hiranvikas77, a full example:
BTW: Works flawlessly if you want to use Reactstrap. Just
import Input from reactstrap/lib/Input
, then replaceinput
withInput
. Of course the popup styles are a bit different.You can still use a SFC as your
CustomDateInput
if you want.The solution is to use React’s
forwardRef
.You can update your
./customDateInput.js
file to look like this…Note that
customDateInput
cannot havepropTypes
ordefaultProps
declarations since it isn’t exactly a React component at this point. It’s merely serving as a render function. (You’d get console warnings if specify propTypes or defaultProps)Resources: