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"
。深くは渡されません。
それを解決する方法を考えていただければ幸いです。