Difference between REF and INNERREF in reactjs Difference between REF and INNERREF in reactjs reactjs reactjs

Difference between REF and INNERREF in reactjs


innerRef is a component instance property, while ref is a component instance attribute:

When the ref attribute is a callback function, the function receives the underlying DOM element or class instance.

// Access reference within the parent component: this.xRef.current// Access property within the component: this.props.innerRef.current<Ycomponent ref={this.xRef} innerRef={this.xRef} />// coolRef is an ordinary component property, you can name it as you like<Ycomponent ref={this.xRef} coolRef={this.xRef} />// access with this.props.coolRef.current within the component.

In conclusion, the custom component Ycomponent defines the property innerRef for the developer to pass a reference with it.

For more info see related question: Why, exactly, do we need React.forwardRef?