【问题标题】:Must specify either a render prop, a render function as children, or a component prop to Field(auto)必须指定一个渲染道具,一个渲染函数作为子级,或者一个组件道具到 Field(auto)
【发布时间】:2020-01-20 18:12:13
【问题描述】:

我在使用 final-form 开发 Auto complete 时遇到错误

必须将渲染道具、渲染函数指定为子级,或将组件道具指定给 Field(auto)

我从这个链接获得帮助 https://trejgun.github.io/articles/bindings-for-using-final-form-with-material-ui-autocomplete/

但是当我实现上面的代码时,我遇到了错误

这是我的代码 https://codesandbox.io/s/relaxed-breeze-hv58o

 <Field
              name="auto"
              multiple={true}
              component={AutoCompleteWrapper}
              placeholder="First Name"
              options={[{ label: "The Shawshank Redemption", values: 1994 }]}
            />

【问题讨论】:

    标签: javascript reactjs material-ui react-final-form final-form


    【解决方案1】:

    在您的代码和框中,在 test.js 中,您将 AutoCompleteWrapper 导出为 命名 导出:

    export const AutoCompleteWrapper = props => {
    

    但在您的 index.js 文件中,您将其作为 默认值 导入:

    import AutoCompleteWrapper from "./test";
    

    因此,您可以通过以下两种方式之一解决此问题:

    导入命名导出

    import { AutoCompleteWrapper } from "./test";
    

    将您的导出更改为默认值

    const AutoCompleteWrapper = props => {
      ...
    };
    
    export default AutoCompleteWrapper;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多