Hello,
This type error mostly get in scenario when you try to sort the readyonly data array.
For me this was occoured when I tried to sort the direct result from my GraphQL query response data like below:
const sortedData = data.bhangarwalas.sort((a, b) => a?.firstname > b?.firstname ? 1 : -1);
In above, data.bhangarwalas is graphql query response results which is readonly in nature as response.
To fix this issue the solution is quick fix for which I have too google to know the result!
Here is the quick solution:
const sortedData = [...data.bhangarwalas];
sortedData.sort((a, b) => a?.firstname > b?.firstname ? 1 : -1);
In code above, We need to clone or you in other words, copying the “data.bhangarwalas” into new array variable and then over that variable, we need to perform sorting operation, which results us right response.
Hope this help you to solve the quick error or to know what scenario this type of error is generated.
Thanks for reading.
Happy learning!
In today’s fast-paced work environment, meetings are essential but can often feel unproductive. However, by…
Gold is one of the most coveted precious metals in the world, adored for its…
Gold, the shimmering metal synonymous with wealth, power, and beauty, has been deeply intertwined with…
How to Onboard an Intern in a Small, Individual-Based Company Hiring an intern can be…