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 :: js or operator 
Javascript :: update column with find sequelize 
Javascript :: run react native with debugger breakpoint 
Javascript :: node js http request express 
Javascript :: npx for yarn 
Javascript :: screenshot 
Javascript :: code checker javascript 
Javascript :: timer javascript 
Javascript :: react tutorial 
Javascript :: Material-ui Account Balance icon 
Javascript :: sumo multiselect 
Javascript :: how ot make a background color faor evaluationbutton in flutter 
Javascript :: dockument anywhere click fucntion in js 
Javascript :: crud application in mean stack 
Javascript :: can we send image in json in angular 
Javascript :: next js find all the rerenders 
Javascript :: working with binary and base64 data 
Javascript :: file_get_contents api json 
Javascript :: array of alphabets 
Javascript :: javascript get the first day of the month and last day 
Javascript :: server sent events node js + github 
Javascript :: how to make your discord bot respond to specific users 
Javascript :: in which table our redux option values are save 
Javascript :: javascript array game map pdf 
Javascript :: { "data": [ { "title": "", "img": "", "address": "" }, ] } json to html 
Javascript :: detecter un click sur un bouton en jquery 
Javascript :: yellow fever mosquities 
Javascript :: knockout framework 
Javascript :: javascript arrays codeburst 
Javascript :: Code is valid JSON equivalent of the key/value pair shown that also preserves the original value: UPC: 043875 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =