Get up and running with Compound React in minutes
This guide will help you quickly get started with Compound React by walking through a simple example of setting up the provider and using some basic hooks.
First, make sure you have installed Compound React as described in the Installation guide.
To use the hooks provided by Compound React, you need to wrap your application with the CompoundProvider
component:
You can specify which network to connect to by passing the network
prop to the CompoundProvider
:
You can also specify which market to connect to by passing the market
prop:
Once you have set up the provider, you can start using the hooks in your components.
To get information about an asset, you can use the useGetAssetInfo
hook:
To get information about the user’s account, you can use the useGetAccountInfo
hook:
To supply collateral to the protocol, you can use the useSupplyCollateral
hook:
Compound React also provides a set of ready-to-use UI components that work seamlessly with the hooks. These components handle loading states, error handling, and data formatting for you.
Here’s a simple example of using the AssetInfoCard
and InterestRateDisplay
components:
For a more comprehensive UI, you can use the CompoundDashboard
component which combines multiple components into a tabbed interface:
The dashboard includes tabs for:
All UI components accept a className
prop that allows you to customize their appearance using Tailwind CSS classes:
For more information on customizing the components, see the UI Components section.
Here’s a complete example that combines all of the above:
Now that you have a basic understanding of how to use Compound React, you can explore the Hooks section to learn about all the available hooks and how to use them in your application.
Get up and running with Compound React in minutes
This guide will help you quickly get started with Compound React by walking through a simple example of setting up the provider and using some basic hooks.
First, make sure you have installed Compound React as described in the Installation guide.
To use the hooks provided by Compound React, you need to wrap your application with the CompoundProvider
component:
You can specify which network to connect to by passing the network
prop to the CompoundProvider
:
You can also specify which market to connect to by passing the market
prop:
Once you have set up the provider, you can start using the hooks in your components.
To get information about an asset, you can use the useGetAssetInfo
hook:
To get information about the user’s account, you can use the useGetAccountInfo
hook:
To supply collateral to the protocol, you can use the useSupplyCollateral
hook:
Compound React also provides a set of ready-to-use UI components that work seamlessly with the hooks. These components handle loading states, error handling, and data formatting for you.
Here’s a simple example of using the AssetInfoCard
and InterestRateDisplay
components:
For a more comprehensive UI, you can use the CompoundDashboard
component which combines multiple components into a tabbed interface:
The dashboard includes tabs for:
All UI components accept a className
prop that allows you to customize their appearance using Tailwind CSS classes:
For more information on customizing the components, see the UI Components section.
Here’s a complete example that combines all of the above:
Now that you have a basic understanding of how to use Compound React, you can explore the Hooks section to learn about all the available hooks and how to use them in your application.