react-scroll-to-component icon indicating copy to clipboard operation
react-scroll-to-component copied to clipboard

Getting a warning accessing findDOMNode inside render

Open sakin opened this issue 7 years ago • 3 comments

Warning: {COMPONENT} is accessing findDOMNode inside its render(). render() should be a pure function of props and state. It should never access something that requires stale data from the previous render, such as refs. Move this logic to componentDidMount and componentDidUpdate instead.

I could be doing it wrong, my ref looks like this: <tr ref={row => { this.row = row; }} >

sakin avatar Oct 26 '17 14:10 sakin

that looks correct... where are you calling findDOMNode?

zentuit avatar Nov 03 '17 18:11 zentuit

this is coming from here i think. So if you call scrollToComponent inside your render you will get this warning.

sag1v avatar Sep 03 '18 13:09 sag1v

For me the following code made this error: ReactDOM.findDOMNode(this.refs.textInput).focus();

I fixed the issue with this: this.refs.textInput.focus();

My code looks like this:

constructor(props) { super(props); this.textInput = null; } render() { return <input ref="textInput" />; }

Mahdiyeh avatar Feb 17 '21 13:02 Mahdiyeh