CupThread React Native & Expo SDK - v0.1.0
    Preparing search index...

    Function useToggleVote

    • Single shared implementation of optimistic vote toggling used by the list, board, and detail surfaces.

      Parameters

      • client: FeedbackClient

        FeedbackClient used to dispatch the toggle request.

      • userToken: string

        Current user token; toggles are ignored while empty.

      • applyChange: VoteChangeApplier

        Applier that persists a transform into the component's state.

      • Optionaloptions: UseToggleVoteOptions

        Optional configuration options such as error callbacks.

      Returns UseToggleVoteResult

      Guarantees:

      • One in-flight request per item: rapid double-taps fire exactly one network call.
      • Success applies the server truth (voted / voteCount) on top of current state.
      • Failure reverts only the optimistic delta relative to current state, never a stale whole-item snapshot.
      • Surfaces vote errors via voteError, getVoteError, and options.onVoteError.
      const applyVoteChange = useCallback((itemId, transform) => {
      setItems((prev) => prev.map((i) => (i.id === itemId ? transform(i) : i)));
      }, []);
      const { toggleVote, isVoting, voteError } = useToggleVote(client, userToken, applyVoteChange);