我有一个包含forwardRef
的组件AddComment:
function AddComment({ comment, setComment }: Props, ref: Ref<HTMLDivElement>) {
return (<div ref={ref}>
// code...
</div>)
}
export default forwardRef<HTMLDivElement>(AddComment)
在父零部件中:
function Parent() {
const [comment, setComment] = useState('')
const addCommentRef = useRef<HTMLDivElement>(null)
return (<div>
// code ...
<AddComment ref={addCommentRef} comment={comment} setComment={setComment}/>
</div>)
}
我得到了这个错误:
Argument of type '({ comment, setComment }: Props, ref: Ref<HTMLDivElement>) => Element' is not assignable to parameter of type 'ForwardRefRenderFunction<HTMLDivElement, {}>'.
Types of parameters '__0' and 'props' are incompatible.
Type '{}' is missing the following properties from type 'Props': comment, setComment
当我在浏览器上运行时,它运行得很好,但我在VS代码中出现了错误.
我怎么才能解决这个问题呢?