Skip to content

documentchange Figma event isn't fired #24

@Fwerydd

Description

@Fwerydd

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions