0
我基於official example從redux-form-material-ui repo。我的代碼看起來像這樣:使用getRenderedComponent()拋出的redux-form-material-ui總是拋出一個錯誤
import React from 'react';
import { Field } from 'redux-form';
import { TextField } from '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}
/>
);
}
}
我傳遞focus
和withRef
性能僅適用於第一場的錯誤。在此字段中,我總是收到錯誤:Uncaught (in promise) Error: If you want to access getRenderedComponent(), you must specify a withRef prop to Field(…)
我能夠看到ref
和withRef
傳遞給Field
。然後在組件ref="wrappedInstance"
我仍然可以看到withRef="true"
。它不會被傳遞得更深。
我將不勝感激任何想法如何解決它。