JSX migration guide #2485
Montoya
announced in
Announcements
Replies: 1 comment 2 replies
-
Hey guys! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Snaps UI is moving to a new UI library that uses JSX! Here's a guide to migrating for anyone using the old function-based UI components.
1. Update dependencies
Make sure to update the following dependencies in your
package.json
:2. Use
.jsx
or.tsx
Any file that uses JSX UI components will need to be updated to the
jsx
ortsx
format.If you end up changing the input file (the entry point for your Snap, which is usually
index.js
orindex.ts
) then you will also need to update this in a couple files:snap.config.ts
, updateSnapConfig.input
to beresolve(__dirname, 'src/index.tsx')
tsconfig.json
, update"include"
to also allowjsx
and/ortsx
files:[..., "**/*.jsx", "**/*.tsx"]
3. Add
jsx
to the compiler optionsIn
tsconfig.json
, add thejsx
compiler option:4. Update dependencies with
yarn
Run
yarn
on the command line to update the dependencies5. Import JSX components from
@metamask/snaps-sdk/jsx
Replace your components import with something like this:
import { Box, Text, Button } from '@metamask/snaps-sdk/jsx'
The components mostly match 1:1, except that now instead of
panel()
you can use<Box>
!6. Return JSX for UI instead of an array of function-based components
An example of JSX being used in
snap_createInterface
:Make sure to wrap the JSX in parens
( )
when using multiple lines.Here is a video showing the Hello World Snap being migrated to JSX. It took about 10 minutes!
https://youtu.be/SgKTIYwmgfA
You can find the code changes in this PR: https://github.com/Montoya/hello-world-snap/pull/28/files
Beta Was this translation helpful? Give feedback.
All reactions