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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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
.jsxor.tsxAny file that uses JSX UI components will need to be updated to the
jsxortsxformat.If you end up changing the input file (the entry point for your Snap, which is usually
index.jsorindex.ts) then you will also need to update this in a couple files:snap.config.ts, updateSnapConfig.inputto beresolve(__dirname, 'src/index.tsx')tsconfig.json, update"include"to also allowjsxand/ortsxfiles:[..., "**/*.jsx", "**/*.tsx"]3. Add
jsxto the compiler optionsIn
tsconfig.json, add thejsxcompiler option:4. Update dependencies with
yarnRun
yarnon the command line to update the dependencies5. Import JSX components from
@metamask/snaps-sdk/jsxReplace 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