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

React Widget onQuestionChanged causes form to keep reloading #665

Closed
teamclouday opened this issue Aug 30, 2024 · 1 comment
Closed

React Widget onQuestionChanged causes form to keep reloading #665

teamclouday opened this issue Aug 30, 2024 · 1 comment
Labels
bug Something isn't working new Flag for new issues before someone replies question Further information is requested

Comments

@teamclouday
Copy link

Hi, I'm working on a react embed Widget component and trying to change an react state whenever question has changed. However it causes the form to keep reloading so it always displays the first question.

Here's an example to reproduce the error:

const [animateValue, setAnimateValue] = React.useState<number>(0);

// ... other code

<Widget
          id={typeformID}
          width="100%"
          height="100%"
          className="z-20 min-h-full min-w-full"
          opacity={0}
          inlineOnMobile
          onQuestionChanged={() => {
            console.log("Question changed");
            setAnimateValue((prev) => (prev + 1) % 3);
          }}
/>

Not sure if this is a bug or there's a better way to do this. I'm using 4.1.0 version of @typeform/embed-react

@github-actions github-actions bot added bug Something isn't working new Flag for new issues before someone replies question Further information is requested labels Aug 30, 2024
@teamclouday
Copy link
Author

I read the troubleshooting page and it turns out I had to wrap both onSubmit and onQuestionChanged in React.useCallback functions and the form will stop reloading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new Flag for new issues before someone replies question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant