Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is proc and method in react javascript?

I'm learning about HOC from this article but have not see proc and method before. What does those refer to?

function refsHOC(WrappedComponent) {
  return class RefsHOC extends React.Component {
    proc(wrappedComponentInstance) {
      wrappedComponentInstance.method()
    }

    render() {
      const props = Object.assign({}, this.props, {ref: this.proc.bind(this)})
      return <WrappedComponent {...this.props}/>
    }
  }
}
like image 905
stackjlei Avatar asked Sep 22 '16 00:09

stackjlei


1 Answers

this.proc refers to the method

proc(wrappedComponentInstance) {
  wrappedComponentInstance.method()
}

wrappedComponentInstance.method() is a just an example of how to call an arbitrary method on the wrapped component. The article says:

In the following example we explore how to access instance methods and the instance itself of the WrappedComponent via refs


So, neither has anything to do with React specifically.

like image 191
Felix Kling Avatar answered Oct 04 '22 03:10

Felix Kling