child hooks not rerendering after changing state in parent hooks

Below are parent component and child component, I just want to update child component once changing state in parent component.

I am creating one table which is child component and passing data from parent to child, and triggering delete function from child to parent. Data is getting deleted in parent but not sending same to child.

Any help is appreciable!!


import React, { useState } from "react";
import Pagination from "./components/Pagination.js";
import { Table } from "./components/Table.js";
import { useEffect } from "react";
import "./App.css";

function App() {

  const [tableData, setTableData] = useState([]);

  useEffect(() => {
      .then(response => response.json())
      .then(data => setTableData(data))

  }, [])

  const deleteRowData = (id) => {, ind) => {
      if (id === {

        tableData.splice(ind, 1);

  // console.log(tableData)
  return (
    <div className="App">
      <div className="container py-4">
        <Table tableData={tableData} deleteRowData={deleteRowData} />

export default App;


import react from "react";
import { useEffect } from "react";
export const Table = (props) => {
    console.log("table component");

    return (<div><table>
            {, ind) => {
                return (<tr key={}>
                    <td onClick={() => props.deleteRowData(}>Delete</td>




>Solution :

Problem is that you are modifying array and setting new state passing same array (reference to same array) and react by default does not re-render child data if state does not change as shallow comparison is made.

Instead modify deleteRowData. You need to create new array (in this case filter takes current array and and returns new array without modifying old one);

    const deleteRowData = (id) => {
        const updatedData = tableData.filter(row => !== id);

Leave a Reply