What are selectors in redux?

前端 未结 4 426
迷失自我
迷失自我 2020-12-23 16:22

I am trying to follow this code in redux-saga

export const getUser = (state, login) => state.entities.users[login]
export const getRepo = (st         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 17:01

    getUser is not a reducer, it is indeed a selector, that is, a function that knows how to extract a specific piece of data from the store.

    Selectors provide an additional layer such that if you altered your store structure and all of a sudden your users were no longer at state.entities.users but instead at state.users.objects.entities (or whatever) then you only need to update the getUser selector and not every place in your app where you were making a reference to the old location.

    That makes them particularly handy when it comes to refactoring your Redux store.

提交回复
热议问题