I've found this to be a useful utility for creating reference selectors which simply select members, but can have a long-lived permanently memoized version. As it's type-only it doesn't have any overhead to add it to the bundle.
/** SELECTORS */
type MemberSelectors<T extends RootState> = {
[k in keyof T]?: (state: T) => T[k];
};
/** Memoized selectors for named members */
export const SELECTORS = {
searchPostings: (state) => state.searchPostings,
searchTerms: (state) => state.searchTerms,
focusSavedMs: (state) => state.focusSavedMs,
} as const satisfies MemberSelectors<CacheState>;
I've found this to be a useful utility for creating reference selectors which simply select members, but can have a long-lived permanently memoized version. As it's type-only it doesn't have any overhead to add it to the bundle.