score:3

Accepted answer

array sort mutates

if you mutate there is no change detected since the reference is the same. but sort also returns itself so you can add this code. the spread operator makes a copy and there for changes the reference meaning that your changes will be detected.

const sortedresults = results.sort((a: any, b: any) => {
  return (a[title] > b[title]) ? 1 : ((b[title] > a[title]) ? -1 : 0)
})

return {
        ...state,
        swapi_data: { 
            ...state.swapi_data,
            results: [...sortedresults],
        },
    }

Related Query

More Query from same tag