reactjs - In react JS fields losing focus after first onChange -
i using redux-form when start typing focus goes out first time in react.
in component below, input field loses focus after typing character. while using chrome's inspector, looks whole form being re-rendered instead of value attribute of input field when typing.
please see below code:
<field name='description' // onchange={this.handlechange.bind(this)} //value={this.state.description} component={props => { return ( <mentiontextarea {...props} usertags={usertags} tags={posttags}/> ) }}
mentiontextarea component:
import react, {component, proptypes} 'react' import { mentionsinput, mention } 'react-mentions' import defaultstyle './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
please help!
thanks in advance,
it's common problem people new redux-form please check issue you'll find answer there.
you must define stateless function outside of render() method, or else recreated on every render , force field rerender because component prop different. example official redux-form documentation:
// outside render() method const renderfield = (field) => ( <div classname="input-row"> <input {...field.input} type="text"/> {field.meta.touched && field.meta.error && <span classname="error">{field.meta.error}</span>} </div> ) // inside render() method <field name="myfield" component={renderfield}/>
Comments
Post a Comment