小编Joy*_*Joy的帖子

React useForm 从 TextBox 获取值

我正在使用 React useForm 钩子从表单提交数据。要求是用户在提交之前应该在预览 div 中看到示例数据。如何从输入文本框中获取值并将其显示在输入旁边的 div 中。文档中有 getValue 方法可以使用吗?

<form>
<div class="mb-6">
            <label  class="block mb-2">Enter Title: </label>
            <input  type="text" id="page_text" class="text-white" placeholder="Enter Title" {...register('page_Title',{ required: "Enter Your Title", maxLength: {value:255,message:"Cannot Exceed more 255 Characters" } })}/>
</div>
</form>
<div className= "text-white text-center rounded-xl shadow-xl">
            <h1>Preview</h1>
            <h3>{getValues("page_Title")}</h3>
</div>
Run Code Online (Sandbox Code Playgroud)

reactjs react-hook-form use-form

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

标签 统计

react-hook-form ×1

reactjs ×1

use-form ×1