Answers for "passing ref to child component"

0

passing ref to child component

// Dumb:
export default props =>
    <input type='number' ref={props.setRef} />

// Smart:
class Parent extends Component {
    constructor(props) {
        super(props);
    }

    setRef(ref) {
        this.inputRef = ref;
    }

    render(){
        return <Dumb {...this.props} setRef={this.setRef} />
    }
}
Posted by: Guest on July-16-2021

Code answers related to "passing ref to child component"

Browse Popular Code Answers by Language