I want to access the refs from the render function, and set it to the state.
Here is my code:
export default class App extends Component {
constructor(props) {
super();
this.arr = this.generateTimelineArray();
this.state = {el : 'empty'};
}
componentDidMount() {
this.setState({
el: this.refs.el
});
console.log(this.state.el)
}
render() {
return (
<div className="timeline__container--line" ref="el" ></div>
);
}
I can console.log(this.refs.el)
and the value is logged. But i have to save it to constructor to pass it to another component.
Problem is that the state is not being changed.
What am i doing wrong?
Thanks in advance