是否可以将react

编程入门 行业动态 更新时间:2024-10-26 06:37:58
本文介绍了是否可以将react-datepicker与react hooks表单一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以将react-datepicker与react hooks表单一起使用?我尝试了以下示例:

Is it possible to use react-datepicker with react hooks forms? I tried following sample:

codesandbox.io/s/awesome-shape-j0747?fontsize = 14&hidenavigation = 1& theme = dark

但是没有运气.

import React, { useState } from "react"; import "./styles.css"; import { useForm } from "react-hook-form"; import { Row, Col, Form, FormGroup, Label, Input, Button } from "reactstrap"; import DatePicker from "react-datepicker"; export default function App() { const { register, handleSubmit } = useForm(); const [startDate, setStartDate] = useState(); const [result, setResult] = useState(); const onSearch = event => { setResult(event); }; return ( <div className="App"> <Form onSubmit={handleSubmit(onSearch)}> <Row> <Col> <FormGroup> <Input type="number" name="account" id="account" placeholder="AccountId" innerRef={register({ required: true, maxLength: 20 })} /> </FormGroup> </Col> </Row> <Row> <Col> <DatePicker innerRef={register} name="datetime" className={"form-control"} selected={startDate} onChange={date => setStartDate(date)} showTimeSelect timeFormat="HH:mm" timeIntervals={15} timeCaption="time" dateFormat="MM-dd-yyyy h:mm" /> </Col> </Row> <Button>Submit</Button> </Form> <div>{JSON.stringify(result)}</div> </div> ); }

推荐答案

请查看控制器文档: react-hook-form/api/#Controller

我们正在维护一个codeandbox示例,用于托管大多数外部组件UI库的实现: codesandbox.io/s/react-hook-form-controller-079xx

which we are maintaining a codesandbox example for hosting most the external components UI libs' implementations: codesandbox.io/s/react-hook-form-controller-079xx

<Controller as={ReactDatePicker} control={control} valueName="selected" // DateSelect value's name is selected onChange={([selected]) => selected} name="ReactDatepicker" className="input" placeholderText="Select date" />

更多推荐

是否可以将react

本文发布于:2023-10-09 18:03:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:react

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!