selectorbeginnerfunction getCounter(state) { return state.counter }
function getUsername(state) { return state.user.name }
// In a component:
const count = getCounter(store.getState())
const name = getUsername(store.getState())Selectors decouple components from the shape of the state tree, making refactoring easier.
Selectors are plain functions that extract a specific piece of data from the Redux state tree:
function getCounter(state) { return state.counter }
function getUser(state) { return state.user }
They centralise access to state shape, so if you rename a key you only update the selector β not every component that reads it.
Challenge: Implement three selectors:
getCounter(state) β state.countergetUser(state) β state.usergetUsername(state) β state.user.name