How to retrieve ref to input when HOC used
See original GitHub issueWhen defining an input class as lower order component of Formsy, how does one go about retrieving a ref to the underlying input component?
If an input class is simply:
class Input {
render() {
return (<div><label ...props>{this.props.caption}</label><input ...props/></div>);
}
export default Formsy.HOC(Input);
And the form:
class AForm {
componentWillReceiveProps() {
// How to access the input component? this.refs.input refers to the HOC of Input.
}
render() {
return (
<Form>
<Input ref="input" ...props/>
</Form>
);
}
}
Say I would like the Input class to allow for the focus to be set programmatically on its {input,textarea} element; how would I go about doing so? How would such an interface be exposed from Input
above?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7
Top Results From Across the Web
How to pass inner ref and use it inside a HOC - Stack Overflow
I want to forward the inner Input ref through FancyInput , and also use the same ref inside the FancyInput , like calling...
Read more >Using React.forwardRef() and an HOC on the same component
Focus management in React currently has one solution: refs. If you want a function component to accept a ref, you should use React....
Read more >Forwarding Refs - React
In the example below, FancyButton uses React.forwardRef to obtain the ref passed to it, and then forward it to the DOM button that...
Read more >How to Use React Refs - Ross Bulat - Medium
Refs at a high level ... Refs are created using React.createRef() , and are assigned to class properties. In the above example the...
Read more >Fullstack React's Guide to using Refs in React Components
A guide to React Refs - Forward Refs (HOC) ... In the example app above, every keypress in the input field is logged...
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 FreeTop 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
Top GitHub Comments
The HOC passes all props through to the component it is wrapping, so you can simply use a callback ref to achieve your goal.
https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute
Foo
andApp
are not HOC @ggd543