Table will initialize 4 times when using React StrictMode

Table will initialize 4 times when using React StrictMode

chocchoc Posts: 95Questions: 11Answers: 8
edited October 9 in Free community support

Link to test case: https://stackblitz.com/edit/datatables-net-react-events-hfpnzk?file=src%2FApp.tsx
Description of problem:
When using development mode, the table is initialized 4 times!

But in production mode, it only initializes once.

This is very confusing and I have know idea why it happens.

I know that this is caused by the use of <StrictMode> but I wonder if there is a way to prevent it being called 4 times (why not just 2 times) during development even with <StrictMode>?

I tried with retrieve set to true but it doesn't work.

This is causing some potential issues, e.g., settings.aaSorting will become empty array since destroy() is being called.
I have a custom sorting indicator React component which replies on the value of settings.aaSorting.

And because of this, I finally know why this post got errors when using language.url

After removing the <StrictMode>, the language.url can work without any issue:

@JuanchiBM You may want to have a check (below demo) if this can solve your issue of using language.url after removing <StrictMode> in main.tsx

https://stackblitz.com/edit/datatables-net-react-simple-1qvkgp?file=src%2FApp.tsx

Sign In or Register to comment.