How do I write this JavaScript code in React js. This piece of code works perfectly fine in JavaScript but does'nt work in React js

Viewed 27

This piece of code works perfectly fine in JavaScript but does'nt work in React js. I tried using arrow function but still unable to get the proper output. please let me know what is the mistake.

 function addLisHandlers() {
          var lis = document.getElementById("name");
          var rows = lis.getElementsByTagName("li");
          console.log(rows);
          for (i = 0; i < rows.length; i++) {
            var currentRow = rows[i];
            var createClickHandler = function (row) {
              return function () {
                author = row.innerHTML;
                document.getElementById("input").value = author;
                return search_button();
              };
            };enter code here
            currentRow.onclick = createClickHandler(currentRow);
          }
        }
0 Answers
Related