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 .
I shared few of those I use the most in a blog post btw. https://6zvwc-sqaaa-aaaal-aalma-cai.raw.ic0.app/d/typescript-utilities-for-candid-on-the-ic
There is also a library we maintain - @dfinity/utils
- which contains quite few handy converters https://github.com/dfinity/ic-js/tree/main/packages/utils
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
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.
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
Thank you, interesting!