Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs innerRef到第三方组件_Reactjs_React Redux_Redux Form_Styled Components - Fatal编程技术网

Reactjs innerRef到第三方组件

Reactjs innerRef到第三方组件,reactjs,react-redux,redux-form,styled-components,Reactjs,React Redux,Redux Form,Styled Components,我正在使用Redux表单和样式化组件 我想得到Redux表单字段的ref,这样我就可以在某些条件下聚焦它 代码看起来像:(稍微简化了一点) 问题在于innerRef的此值未定义。是否有办法访问文本区域的ref,并在必要时对其进行聚焦 (FormLabel也是一个已设置样式的组件,但没有必要显示它以解决问题) 提前谢谢。哇!我编写了redux表单,我喜欢样式化组件,但我从未想过要做样式化(字段)。这是相当荒谬的,因为我不认为字段是一个可以“样式化”的“渲染组件”。 但是,我认为您缺少的难题是您需要

我正在使用Redux表单和样式化组件

我想得到Redux表单字段的ref,这样我就可以在某些条件下聚焦它

代码看起来像:(稍微简化了一点)

问题在于
innerRef
此值未定义。是否有办法访问
文本区域的ref,并在必要时对其进行聚焦

FormLabel
也是一个已设置样式的组件,但没有必要显示它以解决问题)


提前谢谢。

哇!我编写了
redux表单
,我喜欢
样式化组件
,但我从未想过要做
样式化(字段)
。这是相当荒谬的,因为我不认为<代码>字段<代码>是一个可以“样式化”的“渲染组件”。 但是,我认为您缺少的难题是您需要传递到
字段
,这将使您能够使用
getRenderedComponent()
获得实际的
textarea
组件。比如:

<CommentTextArea
  name="comment"
  component="textArea"
  maxLength="250"
  withRef
  innerRef={commentBox => this.commentBox = commentBox.getRenderedComponent()}
/>
this.commentBox=commentBox.getRenderedComponent()}
/>
我只是在猜测。我自己从来没有尝试过这种模式

const CommentTextArea = styled(Field)`
  background-color: grey;
  border-radius: 3px;
  color: black;
  height: 6.5rem;
  margin-bottom: 1rem;
`;
<CommentTextArea
  name="comment"
  component="textArea"
  maxLength="250"
  withRef
  innerRef={commentBox => this.commentBox = commentBox.getRenderedComponent()}
/>