I'm struggling on using a hook on each item on an array within my React Typescript project.
Without considering the limitations on using hooks, the code would be the following:
const forwardContractArray = useGetForwardArray()
interface ForwardResult {
token: string;
amount: number;
expiryTime: number;
}
const forwardResultArray: Array<ForwardResult> = []
for (let forwardAddress of forwardContractArray) {
const { token, amount, expiryTime} = useForwardInfo(forwardAddress)
forwardResultArray.push({token, amount, expiryTime})
}
Because of the limitations on running hooks in a for loop this is not possible to use a for loop for this.
Please could someone direct me on how to implement such a function within the scopes of React?
Thanks in advance.
useForwardInfoshould be returning an array, or you should be rendering a unique component for each usage ofuseForwardInfo.