How to display object inside of a function in React?

I can’t access to “transaction” object from outside of a function, i just want to display transaction details on the screen.
I can see the response into browser’s network tab but can’t display on the page.
Here is my code:

import React from "react";
import { useMoralisWeb3Api } from "react-moralis";

const GetTransaction = () => {
  const Web3Api = useMoralisWeb3Api();

  const options = {
    chain: "eth",

  const fetchTransaction = async () => {
    const transaction = await Web3Api.native.getTransaction(options);
    return <h1> {JSON.stringify(transaction)} </h1>;

  return (
      <button onClick={() => fetchTransaction()}>
        Get Transaction Details

export default GetTransaction;

maybe you can use useState and useEffect

1 Like

I handled it with useState, thanks :slight_smile:

1 Like