webapp/channels/src/selectors/CLAUDE.OPTIONAL.md
selectors/selectors/
├── *.ts # Domain-specific selectors (drafts.ts, rhs.ts, etc.)
└── views/ # UI state selectors matching views/ reducers
Selectors that return new objects or arrays must use createSelector from reselect:
import {createSelector} from 'mattermost-redux/selectors/create_selector';
// GOOD - memoized
export const getVisibleChannels = createSelector(
'getVisibleChannels',
(state: GlobalState) => state.entities.channels.channels,
(channels) => Object.values(channels).filter(c => c.visible),
);
When a selector takes arguments, use a makeGet... factory for per-instance memoization:
// Factory creates a new memoized selector instance
export function makeGetChannel() {
return createSelector(
'getChannel',
(state: GlobalState) => state.entities.channels.channels,
(state: GlobalState, channelId: string) => channelId,
(channels, channelId) => channels[channelId],
);
}
// Functional component - memoize the selector instance
function ChannelItem({channelId}: Props) {
const getChannel = useMemo(makeGetChannel, []);
const channel = useSelector((state) => getChannel(state, channelId));
}
mattermost-redux selectors, re-export or compose them locally for clarity.webapp/STYLE_GUIDE.md → Redux & Data Fetching → Selectors.drafts.ts: Memoized selectors with createSelector.views/modals.ts: Modal state selectors.