这段代码指的是哪个 setInputValue?
Which setInputValue is this code referring to?
我在学习 React 的第 2 天,我不明白下面的代码指的是哪个 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>
</>
)
}
打开 SearchCollections 组件。很可能您没有使用状态管理工具,而是将挂钩传递给该组件以使用它。
我在学习 React 的第 2 天,我不明白下面的代码指的是哪个 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>
</>
)
}
打开 SearchCollections 组件。很可能您没有使用状态管理工具,而是将挂钩传递给该组件以使用它。