小编skw*_*wFE的帖子

使用react-hook-form手表计算字符数

目前,我正在使用react-hook-form进行表单传输。而且,我想渲染输入和文本区域中包含的字符数。

我实现的代码如下。

<input
  id="title"
  type="text"
  placeholder="title"
  {...register('title', {
    required: true,
  })}
/>
<span>
  {watch('title').length}/20
</span>

Run Code Online (Sandbox Code Playgroud)

如上所示,我尝试渲染通过watch输入的字符数,但失败了。你如何表示字符数?

watch reactjs react-hook-form

1
推荐指数
1
解决办法
1839
查看次数

标签 统计

react-hook-form ×1

reactjs ×1

watch ×1