Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
react docs improvements (#517)
Browse files Browse the repository at this point in the history
* react docs improvements

* lint
  • Loading branch information
joaquim-verges authored Jul 17, 2024
1 parent 375501b commit 2c7af13
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 95 deletions.
25 changes: 14 additions & 11 deletions src/app/typescript/v5/react-native/getting-started/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ We recommend starting a new thirdweb React Native project using our CLI, which s
In your CLI, run:

```bash
npx thirdweb create --react-native
npx thirdweb create --legacy-peer-deps --react-native
```

or clone the [expo-starter](https://github.com/thirdweb-dev/expo-starter) repo using git.

<GithubTemplateCard
title="Expo + thirdweb demo repo"
descrption="A starter template for using the thirdweb package in a React Native app"
href="https://github.com/thirdweb-dev/expo-starter"
/>

### Manual Installation

To manually install the React Native SDK, you'll need to install the `@thirdweb/react-native-adapter` package from npm on top of the `thirdweb` package.
Expand Down Expand Up @@ -48,9 +56,13 @@ amazon-cognito-identity-js // for authentication
react-native-aes-gcm-crypto // for encryption
react-native-quick-crypto@0.7.0-rc.6 // for fast hashing

// optional for coinbase wallet
// needed for coinbase wallet
@coinbase/wallet-mobile-sdk
react-native-mmkv

// needed for UI components
react-native-svg
@react-native-clipboard/clipboard
```

</Step>
Expand Down Expand Up @@ -161,12 +173,3 @@ If the Expo CLI says "Using Expo Go" when starting the app, press `s` to switch

</Callout>

### Starter app

If you want to get started quickly run `npx thirdweb create --react-native`, or clone the [expo-starter](https://github.com/thirdweb-dev/expo-starter) repo using git.

<GithubTemplateCard
title="Expo + thirdweb demo repo"
descrption="A starter template for using the thirdweb package in a React Native app"
href="https://github.com/thirdweb-dev/expo-starter"
/>
31 changes: 20 additions & 11 deletions src/app/typescript/v5/react-native/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Callout } from "@doc";

You can use all of the `thirdweb` and `thirdweb/react` exports in your React Native app, with some exceptions (see differences).

## Get Started
## Quickstart

Many of the components and hooks in the React Native SDK use a [`client`](/typescript/v5/core/client) to interface with the core SDK and your private RPC endpoints. You'll need to create a `clientId` in the [Dashboard](https://thirdweb.com/create-api-key) to generate this client.

Expand All @@ -27,14 +27,33 @@ Many of the components and hooks in the React Native SDK use a [`client`](/types
title="Getting started"
icon={ZapIcon}
href="/typescript/v5/react-native/installation"
description="Get started with the React Native SDK"
/>

<ArticleIconCard
title="Differences from React"
icon={ComponentIcon}
href="/typescript/v5/react-native/differences"
description="Get to know the differences between React and React Native usage"
/>

## Starter kit

If you want to get started quickly run:

```bash
npx thirdweb create --legacy-peer-deps --react-native
```

or clone the [expo-starter](https://github.com/thirdweb-dev/expo-starter) repo using git.

<GithubTemplateCard
title="Expo + thirdweb starter repo"
descrption="A starter template for using the thirdweb package in a React Native app"
href="https://github.com/thirdweb-dev/expo-starter"
/>


## Usage

<ArticleIconCard
Expand All @@ -52,13 +71,3 @@ Many of the components and hooks in the React Native SDK use a [`client`](/types
/>

</Stack>

### Starter app

If you want to get started quickly run `npx thirdweb create --react-native`, or clone the [expo-starter](https://github.com/thirdweb-dev/expo-starter) repo using git.

<GithubTemplateCard
title="Expo + thirdweb demo repo"
descrption="A starter template for using the thirdweb package in a React Native app"
href="https://github.com/thirdweb-dev/expo-starter"
/>
53 changes: 53 additions & 0 deletions src/app/typescript/v5/react/connecting-wallets/hooks/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ArticleIconCard, createMetadata, DocImage, Stack } from "@doc";
import { Wallet2Icon } from "lucide-react";
import { ComponentIcon } from "lucide-react";

export const metadata = createMetadata({
image: {
title: "Connecting Wallets",
icon: "react",
},
title: "Connecting Wallets in thirdweb React SDK",
description:
"Connect wallets using ConnectButton, ConnectEmbed or useConnect hook",
});

# Connecting Wallets

## Using Hooks

You can build a completely custom UI for connecting the wallet using the [`useConnect`](/references/typescript/v5/useConnect) hook to connect any of [supported wallets](/typescript/v5/supported-wallets).

```tsx
import { createThirdwebClient } from "thirdweb";
import { useConnect } from "thirdweb/react";
import { createWallet, injectedProvider } from "thirdweb/wallets";

const client = createThirdwebClient({ clientId });

function Example() {
const { connect, isConnecting, error } = useConnect();
return (
<button
onClick={() =>
connect(async () => {
// create a wallet instance
const metamask = createWallet("io.metamask"); // autocomplete the wallet id
// trigger the connection
await metamask.connect({ client });
// return the wallet
return metamask;
})
}
>
Connect
</button>
);
}
```

Refer to [`createWallet`](/references/typescript/v5/createWallet) and [`injectedProvider`](/references/typescript/v5/injectedProvider) for more information.

## Post Connection

Once the wallet is connected, you can use the [Wallet Connection hooks](/references/typescript/v5/hooks#wallet-connection) to get information about the connected wallet like getting the address, account, etc
90 changes: 23 additions & 67 deletions src/app/typescript/v5/react/connecting-wallets/page.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { ArticleIconCard, createMetadata, DocImage, Stack } from "@doc";
import { Wallet2Icon } from "lucide-react";
import ConnectWalletHeroImage from "../components/ConnectButton/images/connect-wallet-hero.webp";
import { ComponentIcon } from "lucide-react";
import {
ZapIcon,
ScrollTextIcon,
ArrowRightLeftIcon,
WalletIcon,
BlocksIcon,
CodeIcon,
FolderTreeIcon,
PlugZapIcon,
ComponentIcon,
CableIcon,
} from "lucide-react";

export const metadata = createMetadata({
image: {
Expand All @@ -15,76 +24,23 @@ export const metadata = createMetadata({

# Connecting Wallets

The SDK supports 350+ wallets out of the box, all you need to pass is their id.
Use the prebuilt UI components or create your own UX with hooks to connect wallets in your app.

<Stack>

<ArticleIconCard
title="Supported Wallets"
title="Using UI Components"
icon={ComponentIcon}
href="/typescript/v5/supported-wallets"
description="See all 350+ wallets supported by the Connect SDK"
description="Prebuilt UI components for connecting wallets"
href="/typescript/v5/react/connecting-wallets/ui-components"
/>

</Stack>

## Using Components

You can use [`ConnectButton`](/typescript/v5/react/components/ConnectButton) or [`ConnectEmbed`](/typescript/v5/react/components/ConnectEmbed) component for a quick, easy and customizable UI.

These components provide a beautiful UI for connecting various wallets and take care of a lot of wallet-specific edge cases - so you can focus on building your app.

These components support over 300+ wallets, including support in-app wallets and account abstraction.

It also automatically shows all installed `EIP-6963` compliant wallet extensions installed by the user.

<DocImage src={ConnectWalletHeroImage} />

## Using Hooks

You can build a completely custom UI for connecting the wallet using the [`useConnect`](/references/typescript/v5/useConnect) hook to connect any of [support wallets](/typescript/v5/wallets).

Refer to [`createWallet`](/references/typescript/v5/createWallet) and [`injectedProvider`](/references/typescript/v5/injectedProvider) for more information.

```tsx
import { createThirdwebClient } from "thirdweb";
import { useConnect } from "thirdweb/react";
import { createWallet, injectedProvider } from "thirdweb/wallets";

const client = createThirdwebClient({ clientId });

function Example() {
const { connect, isConnecting, error } = useConnect();
return (
<button
onClick={() =>
connect(async () => {
const metamask = createWallet("io.metamask"); // pass the wallet id

// if user has metamask installed, connect to it
if (injectedProvider("io.metamask")) {
await metamask.connect({ client });
}

// open wallet connect modal so user can scan the QR code and connect
else {
await metamask.connect({
client,
walletConnect: { showQrModal: true },
});
}

// return the wallet
return metamask;
})
}
>
Connect
</button>
);
}
```
<ArticleIconCard
title="Using Hooks"
icon={CableIcon}
href="/typescript/v5/react/connecting-wallets/hooks"
description="Hooks for connecting wallets with your own UX"
/>

## Post Connection
</Stack>

Once the wallet is connected, you can use the [Wallet Connection hooks](/references/typescript/v5/hooks#wallet-connection) to get information about the connected wallet like getting the address, account, etc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ArticleIconCard, createMetadata, DocImage, Stack } from "@doc";
import { Wallet2Icon } from "lucide-react";
import ConnectWalletHeroImage from "../../components/ConnectButton/images/connect-wallet-hero.webp";
import { ComponentIcon } from "lucide-react";

export const metadata = createMetadata({
image: {
title: "Connecting Wallets",
icon: "react",
},
title: "Connecting Wallets in thirdweb React SDK",
description:
"Connect wallets using ConnectButton, ConnectEmbed or useConnect hook",
});

# Connecting Wallets (UI Components)

## Using Components

You can use [`ConnectButton`](/typescript/v5/react/components/ConnectButton) or [`ConnectEmbed`](/typescript/v5/react/components/ConnectEmbed) component for a quick, easy and customizable UI.

These components provide a beautiful UI for connecting various wallets and take care of a lot of wallet-specific edge cases - so you can focus on building your app.

These components support over 300+ wallets, including support in-app wallets and account abstraction.

It also automatically shows all installed `EIP-6963` compliant wallet extensions installed by the user.

<DocImage src={ConnectWalletHeroImage} />

The SDK supports 350+ wallets out of the box, all you need to pass is their id.

<Stack>

<ArticleIconCard
title="Supported Wallets"
icon={ComponentIcon}
href="/typescript/v5/supported-wallets"
description="See all 350+ wallets supported by the Connect SDK"
/>

</Stack>

## Post Connection

Once the wallet is connected, you can use the [Wallet Connection hooks](/references/typescript/v5/hooks#wallet-connection) to get information about the connected wallet like getting the address, account, etc

18 changes: 16 additions & 2 deletions src/app/typescript/v5/react/extensions/page.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { Details, ArticleIconCard, Stack } from "@doc";
import {
BlocksIcon,
} from "lucide-react";

# Extensions

## Read extensions
Get familiar with the concept of extensions and how to use them in your project.

<ArticleIconCard
title="Understanding Extensions"
description="Learn how to use extensions in your project"
icon={BlocksIcon}
href="/typescript/v5/extensions"
/>

## Using read extensions in React

Any extension that reads from the blockchain can be used with `useReadContract`. The extension function itself be passed as the first argument, and the extension's parameters must be passed as the second argument.

Expand All @@ -23,7 +37,7 @@ const MyComponent = () => {
};
```

## Write extensions
## Using write extensions in React

For extensions that write to the blockchain, they work the same way as raw contract calls using `useSendTransaction`.

Expand Down
Loading

0 comments on commit 2c7af13

Please sign in to comment.