Skip to content

Enhance React Hooks Example Components#13

Merged
GuiBibeau merged 3 commits intosolana-foundation:mainfrom
leandrogavidia:small-additions-to-react-hook-examples
Nov 21, 2025
Merged

Enhance React Hooks Example Components#13
GuiBibeau merged 3 commits intosolana-foundation:mainfrom
leandrogavidia:small-additions-to-react-hook-examples

Conversation

@leandrogavidia
Copy link
Contributor

Summary

This PR improves the developer experience in the React hooks examples by enhancing error handling, data formatting, and providing better guidance for users working with the demo application.

Changes

1. AccountInspectorCard Improvements (03c2b91)

Enhanced the account data display and error handling in the Account Inspector component:

  • Better data formatting: Added smart handling for different data types

    • Uint8Array data now displays as formatted hex bytes (first 100 bytes with truncation indicator)
    • BigInt values are properly converted to strings in JSON output
    • Complex objects show type information and available keys when JSON stringification fails
  • Improved error handling: Added optional chaining (?.) for safer property access to prevent runtime errors when account data is undefined or null

  • Enhanced readability: Account data is now formatted with proper indentation and type-specific rendering for better debugging experience

2. SplTokenPanel UX Enhancement (bee1dc2)

Improved user experience and error handling for SPL token operations:

  • Added faucet link: Included a prominent link to Circle's USDC faucet (https://faucet.circle.com/) to help developers easily obtain test USDC for devnet testing

  • Better error handling: Wrapped the airdrop request in a try-catch block with proper error logging instead of pre-checking RPC capabilities, providing more helpful error messages when operations fail

Testing

  • Verified account inspector displays various data types correctly (Uint8Array, BigInt, complex objects)
  • Confirmed faucet link is visible and functional in the SPL Token panel
  • Tested error scenarios to ensure proper error messages are logged

Impact

These changes make the example application more user-friendly and robust, helping developers understand the framework better through improved error messages and clearer data visualization.

Before

image

After

image

@GuiBibeau GuiBibeau self-requested a review November 21, 2025 08:56
Copy link
Collaborator

@GuiBibeau GuiBibeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moving a bit of stuff around will help future reusability

Comment on lines 23 to 40
if (account?.data instanceof Uint8Array) {
return `Uint8Array(${account?.data?.length} bytes):\n${Array.from(account?.data?.slice(0, 100))
.map((byte) => byte.toString(16).padStart(2, '0'))
.join(' ')}${account?.data?.length > 100 ? '\n... (truncated)' : ''}`;
}
return JSON.stringify(
account?.data,
(_, value) => {
if (typeof value === 'bigint') {
return value.toString();
}
if (value instanceof Uint8Array) {
return `Uint8Array(${value.length})`;
}
return value;
},
2,
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this whole formatter into a util in the example app? I think this might become handy into a formatter package eventually so we should extract it for future use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I added it in utils.ts

<br />
Need test USDC?{' '}
<a
href="https://faucet.circle.com/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it a reusable component for the devnet USDC faucet. I think we'll likely want to showcase that in future places as the demo grows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I put more love into the USDC button.

@GuiBibeau GuiBibeau merged commit affafa8 into solana-foundation:main Nov 21, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants