How to map data from useMoralisQuery

I tried to stringify the json first then use:
but I got Property 'map' does not exist on type 'string'

if I not stringify it I cannot also map it I get
Type 'Object<Attributes>' is not assignable to type 'ReactNode'.

 {transactionResults.map((transaction) => (
                <Tr>
                  <Td>{transaction.ethAddress}</Td>
                  <Td>{transaction.amount</Td>
                </Tr>
              ))}

Try to parse it with json after it was json stringified in order to get an object instead of a string.
The result of json.stringify is a string.

You can also try to use console.log to see how that data looks like

can you give an example please?
TXNRESULTS are the won that is JSON.stringify
DATATXN is the data from useMoralisQuery

I tried:
both data or transactionResults but still got error:

              {Object.keys(data).map((key, i) => (
                <Tr key={i}>
                  <Td>{key.ethAddress}</Td>
                  <Td>$75 BUSD</Td>
                  <Td>Pending</Td>
                  <Td>12 Nov 2022</Td>
                </Tr>
              ))}
               {data.map((key, i) => (
                <Tr key={i}>
                  <Td>{key.ethAddress}</Td>
                  <Td>{key.amount</Td>
                </Tr>
              ))}

found the right mapping
Thank you! solved

  {data.map((key, i) => (
                <Tr key={i}>
                  <Td>{key.attributes.ethAddress}</Td>
                  <Td>{key.attributes.staked}</Td>
                  <Td>Pending</Td>
                  <Td>12 Nov 2022</Td>
                </Tr>
              ))}
1 Like

one more question @cryptokid

how do i know the length of the data of useMoralisQuery?

Im trying to do a loop and add values of the β€œstaked” column? i need to loop and get the total number of data inside it

There should be a way to get the length of that data

yes do you know how?

I don’t know now. How does that object loos like?

If you want to get the length of the array, you can use data.length.

1 Like