JavaScript state is not being set in componentDidMount

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

Answer:1

Someone told me that there's !< and !> in JavaScript. I tried it but it didn't work. Is there something like this in JavaScript? If not in JavaScript, is it there in any other language?

Someone told me that there's !< and !> in JavaScript. I tried it but it didn't work. Is there something like this in JavaScript? If not in JavaScript, is it there in any other language?

  1. javascript there was an error processing the request
  2. is-there javascript
  3. in javascript there are objects of

I am using the Plugins Jquery Dropdown and ListJS. The jQuery Dropdown Plugin offers a hide event: $('.dropdown').on('hide', function(event, dropdownData) { }); In this function I am using the ...

I am using the Plugins Jquery Dropdown and ListJS. The jQuery Dropdown Plugin offers a hide event: $('.dropdown').on('hide', function(event, dropdownData) { }); In this function I am using the ...

  1. working with objects in python
  2. working with objects in powershell
  3. working with objects in java
  4. working with objects in typescript
  5. working with objects in c#
  6. working with objects lesson four
  7. working with objects in php
  8. working with objects in ms word
  9. working with objects in coreldraw
  10. working with objects in react
  11. working with objects in powerpoint
  12. working with objects in illustrator

I was doing the Google's XSS game (https://xss-game.appspot.com/level4) and I managed to solve the 4th level. I didn't completely undestand how, though. I don't understand why if I inject the encoding ...

I was doing the Google's XSS game (https://xss-game.appspot.com/level4) and I managed to solve the 4th level. I didn't completely undestand how, though. I don't understand why if I inject the encoding ...

<div class="container"> <select class="btn" name="item"> <option>Alpha</option> <option>Beta</option> <option>Gamma</option> <...

<div class="container"> <select class="btn" name="item"> <option>Alpha</option> <option>Beta</option> <option>Gamma</option> <...

  1. javascript clone node with event listeners
  2. javascript clone node
  3. javascript clone node without values
  4. javascript clonenode with events
  5. javascript clonenode deep
  6. javascript clone node id
  7. javascript clone node recursive
  8. javascript clone node listeners
  9. javascript clone node dom
  10. js clone node
  11. js clonenode with events
  12. javascript clone html node
  13. javascript clone child node
  14. javascript clone xml node
  15. javascript clone vs clonenode
  16. js clone dom node
  17. js clone html node
  18. vanilla js clone node
  19. clone javascript object node
  20. javascript clone object node js