Wallet re-renders with delay if prop changes, causing flicker #38
-
I'm using the Wallet component with the onSubmit callback to set up the transaction when the button is clicked. When using the Wallet component together with a form - I'm using Formik to validate and submit the form - the button flickers every time any form value changes. This is because the Here's a quick video of what's happening https://tella.video/wallet-re-rendering-on-form-update-fzer I see in Wallet.ts source that there is an initialization delay of 200ms if any of the props updates, and I'm assuming this is what causes the flicker everytime a form value changes. I'm wondering if there is any way to get around this or to disable the init delay? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hello! Good afternoon. The re-renders are caused by the React lifecycle and the usage of Formik. Everytime a prop changes, all the components are re-rendered, and since the Brick is a remote component, it appears to flicker on the screen. This can be fixed by changing the way you implement the component, by using it outside the context of the form you can avoid the issue. |
Beta Was this translation helpful? Give feedback.
Hello! Good afternoon.
The re-renders are caused by the React lifecycle and the usage of Formik. Everytime a prop changes, all the components are re-rendered, and since the Brick is a remote component, it appears to flicker on the screen.
This can be fixed by changing the way you implement the component, by using it outside the context of the form you can avoid the issue.
We created an example that simulates your issue and fixes it using React's
useRef
.Please check it out here, we think it will help you: https://codesandbox.io/s/formik-walletbrick-55wn0q?file=/src/App.js:337-380