Skip to content

Counting problem with character counter for a textarea form field #755

Discussion options

You must be logged in to vote

We found the answer, we used the trips.description.length as the initial state and subtracted it from 150.

export default function EditTrip() {
  const { mutate } = useSWR("/api/trips");
  const router = useRouter();
  const { id } = router.query;
  const { data: trips, isLoading } = useSWR(
    id ? `/api/trips/${id}` : null,
    fetcher
  );
  const [Letters, setLetters] = useState(150 - trips.description.length);
  if (!trips || isLoading) {
    return <h2>is Loading...</h2>;
  }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by StephanBergmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
1 participant