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

documentchange Figma event isn't fired #24

Open
Fwerydd opened this issue Dec 14, 2022 · 2 comments
Open

documentchange Figma event isn't fired #24

Fwerydd opened this issue Dec 14, 2022 · 2 comments

Comments

@Fwerydd
Copy link

Fwerydd commented Dec 14, 2022

Hello,

I'm trying to create a widget to know the last date of update of a component.
For this, I've create a new Widget using the Figma software:
image

And after, in my VSCode, I've copy the following code based on the https://github.com/figma/widget-samples/blob/main/WidgetDocumentChange/widget-src/code.tsx example.

const { widget } = figma
const { useSyncedState, AutoLayout, Text, useEffect } = widget

function Widget() {
  const currentDateDefaultValue = 'XX/XX/XXXX'
  const [currentDate, setCurrentDate] = useSyncedState('currentDate', currentDateDefaultValue);

  useEffect(() => {
    const onDocumentChange = (event: DocumentChangeEvent) => {
      setCurrentDate('TA/TA/TATA');
    };

    figma.on('documentchange', onDocumentChange);
    return () => {
      figma.off('documentchange', onDocumentChange);
    }
  });

  return (
    <AutoLayout>
      <Text fontSize={32} italic={true} width={375} horizontalAlignText={'left'}>
        Updated: {currentDate}
      </Text>
    </AutoLayout>
  )
}
widget.register(Widget);

But my onDocumentChange function is never called.

What I miss?

Regards,

@Bohdan-Anderson
Copy link

Bohdan-Anderson commented Mar 9, 2023

Hey did you figure this out, I'm having the same issue.

@Bohdan-Anderson
Copy link

This question was answered on the Figma Forms
https://forum.figma.com/t/cannot-listen-for-events-in-figjam-widget/35146/5
Basically the widget effect dismounts as soon as it's mounted unless it's waiting for something. We make it wait by using the https://www.figma.com/widget-docs/api/properties/widget-waitfortask/ wait for task function.

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

2 participants