UPDATE3: I have a navbar created by a .map function of each item. When I click in a navbar item, I want to scroll to a specific div of my SPA, to do that , I created a function to scroll to each ref in each div of my page. My problem is that I need to store those refs to get then in my navbar and when I dynamic create those refs I get this error :
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
setMyInputRef2
C:/Users/OMEN/Desktop/Web/tstbst/src/Pages/App.js:62
60 |
61 | setMyInputRef (element) {
> 62 | this.setState( { main : element });
| ^ 63 | };
87 | <div ref={(prop) => {this.setMyInputRef(prop)} }>
where main IS a ref about a div Main
UPDATE4: IT works when I do that:
setMyInputRef = (element) => {
this.setState( { main : element });
};
<div ref={this.setMyInputRef} >
But I want to pass args to my function stMyInputRef to indentify each NavbarItem to store the ref, this way I cant pass that arg to my function
That is what I want :
setMyInputRef = (element,stateRef) => {
this.setState( {"stateRef" : element });
// stateRef as "div1"
};
<div ref={(thisDivRef)=>this.setMyInputRef(thisDivRef,"div1")} >
why I can't do that?
prop, because if this is props, this could be trying to pass the entire props object and its too large? But I'm just spitballing here as it's unclear what you're trying to do exactly