Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda