Skip to content
Discussion options

You must be logged in to vote

Hi 👋

I think you are missing an important point a bit: same as you would call useSelector, you call useQuery wherever you want in your app to retrieve the list. if the selected id is client state and you want to store it in redux to make it globally available, that's fine. Here is how I would probably solve your use-case with react-query and redux:

const useMyList = () => useQuery('myList', () => fetchMyList())

const useMySelectedItem = () => {
    const selected = useSelector(state => state.selectedItem)
    const list = useMyList()

   return list.data?.find(item => item.id === selected.id)
}

useMySelectedItem is now subscribed to the selectedItem in redux, as well as the list data co…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@val2207
Comment options

@TkDodo
Comment options

@tusgavomelo
Comment options

@TkDodo
Comment options

Answer selected by val2207
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants