1

我已经为“Hit”创建了一个类组件,并将其添加到另一个我使用过 angoli react-instantsearch“Hits”的文件中。检查此代码::

<Hits
    hitComponent={Hit}
    className="mb-30"
    showLoadingIndicator
/>

但是给了我一个警告::

警告:道具类型失败:提供给hitComponent的道具类型 无效,应为。objectHitsfunction

我无法将“Hit”转换为功能组件。在这里如何将类组件值用作函数?

4

1 回答 1

1

不确定,但您可以尝试类似的方法:只需将一个函数包装在它周围..一个返回组件的函数

hitComponent={(props) => <Hit {...props} />}

或者

   functions _Hit(props)
    {
    return <Hit {...props} />
    }
     hitComponent={_Hit}
于 2019-08-20T05:35:27.950 回答