Home > OS >  Which setInputValue is this code referring to?
Which setInputValue is this code referring to?

Time:01-23

I'm on 2nd day of learning React and I don't understand which setInputValue is the code below refers to.

At the line const [inputValue, setInputValue] = useState("explore"); setInputValue is a function to set the state. But at line <SearchCollections setInputValue={setInputValue} /> there're two more setInputValue. So which is which? Why is there a setInputValue attribute?

  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"]}

UPDATE: Here's the SearchCollections component.

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>
            
        </>
    )
}

CodePudding user response:

Open up the SearchCollections component. It is very likely that instead of using a state management tool that you are passing down that hook for that component to use it.

  •  Tags:  
  • Related