No internet connection
  1. Home
  2. Programming

Upgrading old React code to react 16

By Aram Mikayelyan @Aram2018-04-25 15:12:21.151Z

Can anyone help me to upgrade this code into react 16?
I'm getting error when I change var to const


  • 3 replies
  1. K
    @KajMagnus2018-04-25 20:20:53.108Z

    Look here: (from the code on the page you linked)

              var index = -1;   
              var clength = this.state.companylist.length;
                for( var i = 0; i < clength; i++ ) {
                    if( this.state.companylist[i].cname === company.cname ) {
                        index = i;

    The variable index gets changed inside the loop. Then you must not use constconst is only for things that won't change, otherwise there'll be an error. Use let instead. (One replaces var with either const or let depending on ... if it's a constant or not)

    What are you building / creating / testing with React b.t.w.? if i may ask

    1. AAram Mikayelyan @Aram2018-04-25 20:48:35.166Z

      I am trying to build a form-table app. The Form must have one input, one textarea and a Add button, which when pressed render a table row with four cells - index, title (first input), desctiption (textarea) and action (delete button for removing the row).
      Here is my unfinished work.

      1. SSarkis @Saqo2018-04-26 03:01:12.687Z

        It's very close to a todo app... There is no shortage of tutorials online for a todo app... However, I would strongly recommend that you brush up on vanilla JS before moving to any framework (library)...