Selectors
Selectors are the API that slices expose for synchronously selecting a part of the state.

Note
Not all slices need to expose selectors. Slices that have queries typically should not expose selectors.

When To Use Selectors:
Selectors are useful in the following scenarios:

When the slice doesn’t fetch data from the server.
When the data is loaded externally (e.g., from a monolith) and directly set into the slice.
In other situations, it’s recommended to use queries, as they have asynchronous API, allow lazy data fetching and are more efficient.

Creating Selectors:
Selectors are pure functions that take the state as an argument and return a part of the state. All Selectors are accessible through the selectors property of the slice. They can be defined directly within the slice or imported from an external file.

class CurrentUserSlice extends BaseSlice<CurrentUser> {
  selectors = {
    selectCurrentUser: (state: RootState) => state.currentUser,
    selectCurrentUserName: (state: RootState) => state.currentUser.name,
  };
}

info
Selectors should be memoized using reselect to avoid unnecessary recalculations and re-renders.