Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
.shift() removing first element before loop

I am trying to remove the first element of the data array using data.shift() but this removes the first element immediately then my column gets a different value. My Code:

import React, { useMemo } from "react";
import useData from "../../hooks/useData";
import Table from "./Table";

const TableSection = ({ query }) => {
  const { data } = useData(query);
  const column =
    data.length > 0 &&
    Object.keys(data[0]).map((key, value) => {
      return {
        Header: data[0][key],
        accessor: key,
      };
    });
data.shift();
  const columns = useMemo(() => column, [column]);
  const queryData = useMemo(() => data, [data]);
  return (
    <div className="col-start-2 col-end-3 row-start-3 row-end-4 mt-3 text-black w-1/2 overflow-x-scroll">
      {data.length > 0 && <Table columns={columns} data={queryData} />}
    </div>
  );
};

export default TableSection;

Anyone please help me with this.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Do not mutate the state of data object inside a functional component. If you want to render all but the first row you can change your queryData memo to be:

const queryData = useMemo(() => data.slice(1), [data])
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!