我已经尝试了一段时间,但没有任何成功。我已经设法实现了 reactstrap + react-hook-form 和 reactstrap + react-input-mask 但没有同时实现这三个。这是运行的代码:https ://stackblitz.com/edit/reactstrap-v5beta-input-mask-yu6zii?file=Example.js
import React from 'react';
import { Input } from 'reactstrap';
import useForm from 'react-hook-form'
import InputMask from 'react-input-mask';
const Example = () => {
const { register, handleSubmit, errors } = useForm()
const onSubmit = data => console.log(data)
console.log(errors)
return (
<div>
<form onSubmit={handleSubmit(onSubmit)}>
<label>react-hook-form</label>
<Input
type='text'
name='input-1'
invalid={errors['input-1']}
innerRef={register({ required: true })}
/>
<br />
<label>react-input-mask</label>
<Input
type="tel"
mask="+4\9 99 999 99"
maskChar=" "
tag={InputMask}
/>
<br />
<input type="submit" />
</form>
</div>
)
}
export default Example;