首页 > 解决方案 > Error using library: Invalid hook call. Hooks can only be called inside of the body of a function component

问题描述

I'm trying to use this library: https://github.com/adarshpastakia/ant-extensions/tree/master/modules/searchbar

I'm testing it on a codesandbox and it should work, but I get this error: **Invalid hook call. Hooks can only be called inside of the body of a function component. **

My code

import "./styles.css";
import { SearchBar } from "@ant-extensions/searchbar";

export default function App() {
  return (
    <div className="App">
      <h1>Hello</h1>
      <SearchBar
        collapsed={false}
        filters={[]}
        fields={[]}
        emptyField={"Message when fields list is empty"}
      />
    </div>
  );
}

Sandbox link: https://codesandbox.io/s/pedantic-snowflake-7c3mz?file=/src/App.js

标签: javascriptreactjstypescriptnpmjsx

解决方案


推荐阅读