0
我使用Redux Form和Styled Components。innerRef第三方组件
我想获得一个Redux表单字段的引用,所以我可以将它集中在某些条件下。
代码看起来是这样的:(一点点简化)
export const SomeForm =() => (
<form onSubmit={handleSubmit} >
<FormLabel htmlFor="comment">Comment:</FormLabel>
<CommentTextArea
name="comment"
component="textArea"
maxLength="250"
innerRef={commentBox => this.commentBox = commentBox}
/>
</form>
);
凡CommentTextArea
像这样的风格的组件:
const CommentTextArea = styled(Field)`
background-color: grey;
border-radius: 3px;
color: black;
height: 6.5rem;
margin-bottom: 1rem;
`;
的问题是,innerRef
的this
值未定义。有没有办法访问textArea
的参考号并在必要时集中它?
(FormLabel
也是一种风格的组成部分,但不是必需的,以显示它的问题)提前
感谢。