reactjs - redux-form-material-ui using getRenderedComponent() throws always an error -
i'm basing on official example redux-form-material-ui repo. code looks that:
import react 'react'; import { field } 'redux-form'; import { textfield } 'redux-form-material-ui'; export default class formtextfield extends react.component { constructor(props) { super(props); } componentwillupdate(nextprops) { const { name, withref, focus } = nextprops; if (withref && focus) { this.refs[name] .getrenderedcomponent() .getrenderedcomponent() .focus(); } } render() { const { name, label, errortext, withref } = this.props; return ( <field name={name} component={textfield} hinttext={label} floatinglabeltext={label} errortext={errortext} ref={name} withref={withref} /> ); } } i'm passing focus , withref properties first field error. on field error: uncaught (in promise) error: if want access getrenderedcomponent(), must specify withref prop field(…)
i' able, see both ref , withref passed field. in component ref="wrappedinstance" can still see withref="true". not passed deeper.
i appreciate thoughts how solve it.
- you needn't make
refprop, local component. can callref="field"if wish. although not problem. - also, might passing
withreftime.
it sounds wanting call focus() when focus prop changes false true. that, should doing like:
componentwillupdate(nextprops) { if (!this.props.focus && nextprops.focus) { this.refs.field .getrenderedcomponent() .getrenderedcomponent() .focus() } } does help?
Comments
Post a Comment