Skip to content

Commit

Permalink
Add JSX upgrade instructions (#1474)
Browse files Browse the repository at this point in the history
* Add JSX upgrade instructions

* edits for syntax and style

* Update snaps/features/custom-ui/with-jsx.md

Co-authored-by: Frederik Bolding <[email protected]>

---------

Co-authored-by: Alexandra Tran <[email protected]>
Co-authored-by: Frederik Bolding <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2024
1 parent 3fb4746 commit b09c614
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions snaps/features/custom-ui/with-jsx.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,54 @@ await snap.request({
Note that JSX can only be used in `.jsx` or `.tsx` files.
:::

## Upgrade an existing Snap to use JSX

Follow these steps to upgrade an existing Snap to use JSX:

1. Upgrade dependencies in `packages/snap/package.json`:

- Upgrade `@metamask/snaps-sdk` to `^6.1.1` or later.
- Upgrade `@metamask/snaps-cli` to `^6.2.1` or later.
- Upgrade `@metamask/snaps-jest` to `^8.2.0` or later.

Run `yarn install` to install the new versions.

2. Update `packages/snap/.eslintrc.js`:

- Add a new section in `overrides` with the following configuration:
```json
{
"files": ["**/*.ts", "**/*.tsx"],
"extends": ["@metamask/eslint-config-typescript"],
"rules": {
// This allows importing the `Text` JSX component.
"@typescript-eslint/no-shadow": [
"error",
{
"allow": ["Text"],
},
],
},
}
```
- Replace `["*.test.ts"]` with `["*.test.ts", "*.test.tsx"]`.

3. Update `packages/snap/src/index.ts`, if it will have JSX:

- Rename the file to `index.tsx`.
- Modify the `input` field in `packages/snap/snap.config.ts` to `src/index.tsx`.

4. Update `packages/snap/tsconfig.json`:

- Under `compilerOptions`, add:
```json
"jsx": "react-jsx",
"jsxImportSource": "@metamask/snaps-sdk"
```
- Change the `include` property from `["**/*.ts"]` to `["**/*.ts", "**/*.tsx"]`.

5. Replace all Custom UI in your code with JSX components, renaming the target files with the `.tsx` extension.

## Components

The following custom UI JSX components are available:
Expand Down

0 comments on commit b09c614

Please sign in to comment.