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

216
Views
useQuery: Attempted to assign to readonly property

I get data from useQuery. And I want to sort them by data field directFeedNumber.

  const { data: allFeedData, loading: allFeedLoading } =
    useQuery(SEE_ALL_FEED_ORDER);

  const FeedSort = allFeedData.seeAllFeedOrder.sort(function (a, b) {
    return a - b;
  });

So I use sort function to do this, but when I console.log FeedSort, it says Attempted to assign to readonly property.

So can't I use sort function with data got from useQuery?

Then how can I sort them? Please help me!!

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

0

Array.sort alters the original array, unlike other methods such as Array.map which produce a new array.

In order to prevent this, we can make a shallow copy of the original array.

Example:

const { data: allFeedData, loading: allFeedLoading } = useQuery(SEE_ALL_FEED_ORDER);

const FeedSort = [...allFeedData.seeAllFeedOrder].sort(function (a, b) {
   return a - b;
});

What we do here is create a new array and populate it with the values of the original array using the spread syntax.

Then we sort the newly created array, which we can alter.


Note: there are also other ways of making shallow copies, or deep copies for that matter, of arrays and objects.
Here are some other examples.

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!