我在學習 React 的第二天,我不明白setInputValue下面的代碼指的是哪個。
在const [inputValue, setInputValue] = useState("explore");setInputValue 行是一個設定狀態的函式。但是在線<SearchCollections setInputValue={setInputValue} />還有兩個 setInputValue。那么哪個是哪個?為什么有 setInputValue 屬性?
const [inputValue, setInputValue] = useState("explore");
useEffect(() => {
if (isAuthenticated && !isWeb3Enabled && !isWeb3EnableLoading) enableWeb3();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isAuthenticated, isWeb3Enabled]);
return (
<Layout style={{ height: "100vh", overflow: "auto" }}>
<Router>
<Header style={styles.header}>
<SearchCollections setInputValue={setInputValue} />
<Menu
theme="light"
mode="horizontal"
style={{
display: "flex",
fontSize: "17px",
fontWeight: "500",
marginLeft: "50px",
width: "100%",
}}
defaultSelectedKeys={["nftMarket"]}
更新:這是 SearchCollections 組件。
import { Select } from 'antd';
import { useMoralisDapp } from "providers/MoralisDappProvider/MoralisDappProvider";
import { getCollectionsByChain } from "helpers/collections";
function SearchCollections({setInputValue}){
const { Option } = Select;
const { chainId } = useMoralisDapp();
const NFTCollections = getCollectionsByChain(chainId);
function onChange(value) {
setInputValue(value);
}
return (
<>
<Select
showSearch
style={{width: "1000px",
marginLeft: "20px" }}
placeholder="Find a Collection"
optionFilterProp="children"
onChange={onChange}
>
{NFTCollections &&
NFTCollections.map((collection, i) =>
<Option value={collection.addrs} key= {i}>{collection.name}</Option>
)
}
</Select>
</>
)
}
uj5u.com熱心網友回復:
打開 SearchCollections 組件。很可能不是使用狀態管理工具,而是傳遞該鉤子以供該組件使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/419533.html
標籤:
