Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

pass ref to class component react

class ElemComponent extends Component {
  render() {
    return (
      <div ref={this.props.innerRef}>
        Div has a ref
      </div>
    )
  }
}

export default React.forwardRef((props, ref) => <ElemComponent 
  innerRef={ref} {...props}
/>);
Comment

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} />
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to remove an item from an array in javascript 
Javascript :: javascript alert html 
Javascript :: parentnode javascript 
Javascript :: color picker in react js 
Javascript :: react doc viewer 
Javascript :: replace javascript 
Javascript :: mongoose autoincrement 
Javascript :: mock click function functinal component enzyme 
Javascript :: reactjs .net pass value to react 
Javascript :: videojs videoJsResolutionSwitcher youtube 
Javascript :: intersection of two objects in javascript 
Javascript :: use axios cancel token in react.js useEffect 
Javascript :: xor operator js 
Javascript :: npm install say unmet dependencies 
Javascript :: install ejs 
Javascript :: save data response from fetch as global param js 
Javascript :: only allow requests from domain express 
Javascript :: juqey off click 
Javascript :: convert boolean to string javascript 
Javascript :: getinitialprops to a hoc in next js 
Javascript :: html2canvas not getting image if file field src is url 
Javascript :: js filter method 
Javascript :: JavaScript: Updating Object Properties 
Javascript :: shopify guest login 
Javascript :: how to Write a program that simulates a coin toss using random method of Javascript Math class 
Javascript :: reactjs wait for image to load from url 
Javascript :: Replace empty strings in object with null values 
Javascript :: search nested array in react javascript 
Javascript :: change color in react 
Javascript :: emergency food 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =