skip to Main Content

Basically, I have a list of products, in this list, I have a favorite function, but when I am logged out and favorite a product, it returns me to the login screen. After logging in, I have to do the favorite process again, I have to find a way when the user clicks on the favorite product when he returns from the login it is already filled in, I am using the Redux toolkit for the states

const addRemoveWishlistItem = async (idProduct: string) => {
    if (!userLogged) return navigation.navigate('/login')

    const isServiceLoading =
      removeWishlistItemQuery.isLoading || addWishlistItemQuery.isLoading

    if (!idWishlist || isServiceLoading) return

    if (favoriteId.includes(idProduct)) {
      store.dispatch(UpdateLastFavoriteAdded(null))
      return removeWishlistItemQuery.mutate(idProduct)
    }

    store.dispatch(UpdateLastFavoriteAdded(idProduct))
    return addWishlistItemQuery.mutate(idProduct)
  }

  const handleDeleteAllFavorites = async () => {
    return removeAllWishlistItemsQuery.mutate()
  } 

2

Answers


  1. Easily, you can store the actions with their related data in the localStorage, and after every login process, first of all, check the localStorage for the queued actions.

    Login or Signup to reply.
  2. On the same line as the last answer, you could have a pre-saved favorite store? maybe you can also use it while the answer from your backend arrive (when you give like to something)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search