[英]TypeScript error: Property 'children' does not exist on type '{ children?: ReactNode; }'
https://www.emgoto.com/react-search-bar/ https://www.emgoto.com/react-search-bar/
I am implementing the search bar from the link above.我正在从上面的链接中实现搜索栏。
But I get a typescript error and I tried to match the type, but it didn't work..但是我得到一个打字稿错误,我试图匹配类型,但它没有用..
Homepage.tsx主页.tsx
const [searchQuery, setSearchQuery] = useState(query || '');
return(
<Search searchQuery={searchQuery} setSearchQuery={setSearchQuery} />
);
Search.tsx搜索.tsx
import React, { FC } from 'react';
const Search: FC = ({ searchQuery, setSearchQuery }) => { // error!
return (
<form action="/" method="get">
<label htmlFor="header-search">
<span className="visually-hidden">Search blog posts</span>
</label>
<input
value={searchQuery}
onInput={(e) => setSearchQuery(e.target.value)}
type="text"
id="header-search"
placeholder="Search blog posts"
name="s"
/>
<button type="submit">Search</button>
</form>
);
};
export default Search;
Error:错误:
Comment from CRice来自 Crice 的评论
React.FC
is a generic type which accepts the type of the props as its parameter. React.FC
是一个泛型类型,它接受 props 的类型作为其参数。 You'll need to include the prop type.您需要包含道具类型。 Example:例子:
const Search: FC<{searchQuery: string, setSearchQuery: (new_query: string) => void}> = ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.