0

App.jsx

<Provider store={store}>
  <Main {...this.props} ref={this.props.setRef}>
</Provider>

I want to set ref in the component. I want to call the method of the main component in my service file using reference.

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Chetan Buddh
  • 452
  • 8
  • 14
  • Does this answer your question? [How to use React.forwardRef in a class based component?](https://stackoverflow.com/questions/51526461/how-to-use-react-forwardref-in-a-class-based-component) – Emile Bergeron May 01 '20 at 14:50

1 Answers1

0

refs only work with DOM element, they don't work with React component. However, if you want a ref to one DOM element rendered by Main, it's possible to do it using forwardRef

HermitCrab
  • 3,194
  • 1
  • 11
  • 10