Sign in
Log inSign up

reactjs method not being called in render method

jim toby's photo
jim toby
·Oct 17, 2018

I have a function to delete elements from an array in the state given its index. Here it is:

removeFromRowsById(index) {
    console.log("IN REMOVE FUNCTION");
    const newList = this.state.rows1;
    newList.splice(index, 1);
    this.setState({ rows1: newList });
  }

I call it in my render method like this:

    this.removeFromRowsById.bind(this, this.state.rows1.indexOf(this.returnValueToDelete(this.state.rows1[1]["id"])))

this.state.rows1.indexOf(this.returnValueToDelete(this.state.rows1[1]["id"])) returns the object inside rows1 that I want removed.

The problem is, when I call it, nothing happens. It seems like it never goes in the method since "IN REMOVE FUNCTION" never gets logged in the console. Any type of help i highly appreciated it. I'm new to reactjs and I've been working on this for quite some time. Thanks!

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct