Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] create-widget-app does not support importing React hooks #4

Closed
hydrosquall opened this issue Nov 30, 2021 · 0 comments
Closed

Comments

@hydrosquall
Copy link

Steps

When code.tsx from the create-widget-app example is modified to a minimal example with state management:

import * as React from "react"

function Widget() {
  const [ text, setText ] = React.useState('Hello World')
 
  return <div>{text}</div> 
}

This error gets logged to the console when you try to import the widget:

SyntaxError: possible import expression rejected around line 1

Screenshot: https://a.cl.ly/GGu4957G

It looks a lot like this error (figma/plugin-typings#36), except it's with a React core library rather than Endo, so it may be harder to patch.

Update

  • I realized after writing this report that React hooks are not permitted in the code.tsx file, but I was confused earlier because they were permitted in the UI panel file. The fix is to use useSyncedState from the figma.widget API instead.

I'm filing this report anyways in case someone googling this error message may benefit and save themselves some trouble 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant