I have an input for users to come and paste one id or multiple with each seperated by a comma then run a function on the individual Id's.
<Input type={'text'} placeholder="Id(s) (seperated by comma if more than 1)" value={ids} onChange={(event) => setIds(event.target.value)} />
Then I have the React useState constants for using the individial ids
const [ids, setIds] = useState(["ID#1", "ID#2"]).split("[\\s,]+")
const [id, setId] = useState(addresses[0]);
Here is where I set the function for picking each individual ID and running the function
const fetchNft = async (e) => {
for(let i = 0; i< ids.length; i++){
const _id = id[i]
const idInfo = await find(_id);
console.log(idInfo)
}
}
This doesn't make any sense:
useStatereturns an array containing the state value and the setter function for the state value. There's nothing to "split", and in this case neither of those values are strings.You probably meant to put that
splitlogic here:Since the input value is the string of comma-separated values that you want to split into an array.