【发布时间】:2017-09-12 09:00:04
【问题描述】:
我正在使用 redux-form 但是当我开始打字时,焦点第一次在反应中熄灭。
在我下面的组件中,输入字段在输入字符后失去焦点。在使用 Chrome 的 Inspector 时,看起来整个表单正在重新呈现,而不仅仅是输入字段的 value 属性。
请看下面的代码:
<Field
name='description'
// onChange={this.handleChange.bind(this)}
//value={this.state.description}
component={props => {
return (
<MentionTextArea {...props} userTags={userTags} tags={postTags}/>
)
}}
MentionTextArea 组件:
import React, {Component, PropTypes} from 'react'
import { MentionsInput, Mention } from 'react-mentions'
import defaultStyle from './defaultStyle'
class MentionTextArea extends Component {
constructor(props) {
super(prop)
}
handleOnChange (e) {
this.props.input.onChange(e.target.value);
}
render() {
// const { input, meta, ...rest } = this.props;
return (
<MentionsInput
value={this.props.input.value || ''}
onChange={this.handleOnChange.bind(this)}
singleLine={false}
style={ defaultStyle }
markup="@[__display__](__type__:__id__)"
>
<Mention trigger="@"
data={this.props.userTags}
type="userTags"
style={{ backgroundColor: '#d1c4e9' }}
renderSuggestion={ (suggestion, search, highlightedDisplay) => (
<div className="user">
{ highlightedDisplay }
</div>
)}
/>
<Mention trigger="#"
data={this.props.tags}
type="tags"
style={{ backgroundColor: '#d1c4e9' }}
renderSuggestion={ (suggestion, search, highlightedDisplay) => (
<div className="user">
{ highlightedDisplay }
</div>
)}
/>
</MentionsInput>
);
}
}
export default MentionTextArea
请帮忙!
提前致谢,
【问题讨论】:
-
你能展示一下你是如何渲染表单的吗
-
let connection = connect(mapStateToProps, mapDispatchToProps) var reduxConnectedComponent = connection(CreatePostForm) export default reduxForm({ form: 'CreatePost' // 此表单的唯一标识符 })(reduxConnectedComponent)
-
您是否在某处提供了唯一生成的密钥。也可以试试
let connection = connect(mapStateToProps, mapDispatchToProps) var reduxConnectedComponent = reduxForm({ form: 'CreatePost' // a unique identifier for this form }) export default connection(reduxConnectedComponent) -
我是 reactJS 的新手,能否请您提供链接或指导我们需要在哪里添加密钥?
标签: reactjs redux react-redux redux-form