In a react frontend would you generally convert the declarations types into something simpler or not?

What‘s best practice?

In NNS-dapp we have both use cases, for Nns types we convert these because we inherited it from past implementation so when we integrated Sns we went with an implementation without conversion which in my opinion is more handy for NNS-dapp.

In my personal apps, I do a bit of both, depends the goal of my dapps.

So all and all when it comes to me, I would say it probably depends. Like a tradeoff between maintanability, readability and to some extent performances.

That said, one thing I do for sure in any apps, is using utilities to convert types because there is no way I want to work with such types [] | [T] in a frontend app :crazy_face::crazy_face::crazy_face:.

I shared few of those I use the most in a blog post btw.

There is also a library we maintain - @dfinity/utils - which contains quite few handy converters

Note: I don’t use React for my dapps but I assumed your question was not stricto sensu limited to React but more generally speaking frontend apps


Thank you very much, that is a very helpful answer!

Haha yeah exactly :joy:
Couldn’t it be converted into something more convenient directly?

I‘ll check out how you built the NNS and SNS frontends, didn’t think of it before.

1 Like

If I understand correctly there is a good reason why it converts to such types. I actually asked the same question when I started on the IC too, before I began to collaborate with the foundation. That was one of the answer Candid code generation for nullable types - #4 by rossberg

1 Like

Thank you, interesting!

1 Like