useOptimistic returns the optimistic state and a dispatch-like function that applies an optimistic update.