-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(hooks): add initial react hooks docs (#561)
* docs(hooks): add initial react hooks docs * refactor: apply suggestions from code review Co-authored-by: Ajay Vasisht <43521356+avasisht23@users.noreply.github.com> --------- Co-authored-by: Ajay Vasisht <43521356+avasisht23@users.noreply.github.com>
- Loading branch information
1 parent
ce3e0b8
commit 5726116
Showing
32 changed files
with
794 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
outline: deep | ||
head: | ||
- - meta | ||
- property: og:title | ||
content: createConfig | ||
- - meta | ||
- name: description | ||
content: An overview of the createConfig function | ||
- - meta | ||
- property: og:description | ||
content: An overview of the createConfig function | ||
- - meta | ||
- name: twitter:title | ||
content: createConfig | ||
- - meta | ||
- name: twitter:description | ||
content: An overview of the createConfig function | ||
--- | ||
|
||
# createConfig | ||
|
||
The `createConfig` method is used to create a configuration object that is used to initialize the `AlchemyAccountProvider`. The output of this function contains all of the state that will be used by the various hooks exported by `@alchemy/aa-alchemy/react`. | ||
|
||
::: warning | ||
It's not recommended to use the resulting config directly. However, if you are not using `React` it is possible to build your own custom hooks using the state contained in the config object. | ||
::: | ||
|
||
## Import | ||
|
||
```ts | ||
import { createConfig } from "@alchemy/aa-alchemy/config"; | ||
``` | ||
|
||
## Usage | ||
|
||
<<< @/snippets/react/config.ts | ||
|
||
## Parameters | ||
|
||
```ts | ||
import { type CreateConfigProps } from "@alchemy/aa-alchemy/config"; | ||
``` | ||
|
||
::: details CreateConfigProps | ||
<<< @/../packages/alchemy/src/config/types.ts#CreateConfigProps | ||
::: | ||
|
||
::: details ConnectionConfig | ||
<<< @/../packages/core/src/client/schema.ts#ConnectionConfigSchema | ||
::: | ||
|
||
## Return Type | ||
|
||
```ts | ||
import { type AlchemyAccountsConfig } from "@alchemy/aa-alchemy/config"; | ||
``` | ||
|
||
Returns an object containing the Alchemy Accounts state. | ||
|
||
### bundlerClient | ||
|
||
`ClientWithAlchemyMethods` | ||
A JSON RPC client used to make requests to Alchemy's Nodes and Bundler. | ||
|
||
### signer | ||
|
||
`AlchemySigner` | ||
The underlying signer instance used by Embedded Accounts. This property is only available on the client. | ||
|
||
### coreStore | ||
|
||
`CoreStore` | ||
This store contains all of the state that can be used on either the client or the server. | ||
|
||
### clientStore | ||
|
||
`ClientStore` | ||
This store contains only the state available on the client. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
outline: deep | ||
head: | ||
- - meta | ||
- property: og:title | ||
content: React Hooks Overview | ||
- - meta | ||
- name: description | ||
content: An overview of using React Hooks exported by Account Kit | ||
- - meta | ||
- property: og:description | ||
content: An overview of using React Hooks exported by Account Kit | ||
- - meta | ||
- name: twitter:title | ||
content: React Hooks Overview | ||
- - meta | ||
- name: twitter:description | ||
content: An overview of using React Hooks exported by Account Kit | ||
--- | ||
|
||
# React Hooks Overview | ||
|
||
If you are using Alchemy's RPC and Smart Contract Accounts and building a React application, you can use the React Hooks exported by Account Kit to interact with your Smart Contract Accounts. You're not required to use these hooks to leverage all of the power of Account Kit. The hooks are exported from `@alchemy/aa-alchemy` and can be found within the `@alchemy/aa-alchemy/react` namespace. | ||
|
||
::: warning | ||
React hooks are still being developed and the interfaces could change in the future! | ||
::: | ||
|
||
## Install the package | ||
|
||
To use the React Hooks, you need to install the `@alchemy/aa-alchemy` and `@tanstack/react-query` packages. We use [`react-query`](https://tanstack.com/query/latest/docs/framework/react/overview) to manage async data fetching and mutations in our hooks. | ||
|
||
::: code-group | ||
|
||
```bash[npm] | ||
npm install @alchemy/aa-alchemy @tanstack/react-query | ||
``` | ||
|
||
```bash[yarn] | ||
yarn add @alchemy/aa-alchemy @tanstack/react-query | ||
``` | ||
|
||
```bash[pnpm] | ||
pnpm add @alchemy/aa-alchemy @tanstack/react-query | ||
``` | ||
|
||
::: | ||
|
||
## Create a config | ||
|
||
In order to get started, you'll first have to define a config object that can be used to create an `AlchemyAccountContext` that will be used by all of the hooks exported by the library. | ||
|
||
::: code-group | ||
<<< @/snippets/react/config.ts | ||
::: | ||
|
||
## Wrap app in Context Provider | ||
|
||
Next, you'll need to add the `AlchemyAccountProvider` to your application and pass in the config object and an instance of the `react-query` `QueryClient`. | ||
|
||
::: code-group | ||
|
||
<<< @/snippets/react/app.tsx | ||
|
||
<<< @/snippets/react/config.ts | ||
::: | ||
|
||
## Use the hooks | ||
|
||
Explore the remaining hooks docs and use them in your application! |
Oops, something went wrong.