Hey guys, with react, how do you decide whether yo...
# javascript
n
Hey guys, with react, how do you decide whether you'd use RComponent, FC function or the RBuilder extension? In regular react I only used functions and arrow functions but then I could return HTML code and put my useStates and logic before that. What's the state of kotlin, I am kinda confused where to put logic and whether to use the classes or the functions. So with these 3 approaches is it up to preference or are there benefits to each one?
t
Function components preferred (see example)
Also only in function components you can use existed wrappers for:
react-popper
reqct-query
react-table
react-virtual
😉
n
@turansky Thank you! That was exactly what I needed to know.
c
For very short chunks of code, you can create a function like this: fun RBuilder.foo(...) { p { +"Hello world" } } That is not a *co*mponent (you can't use hooks, you can't memoize it, etc). However you also don't need to declare props, so sometimes it's convenient.
n
@CLOVIS Hey man I recognize the name, your formulaide got me into switching from classes to functional components, thanks! I am gonna use the RBuilder.() to mostly write reusable atomic components like you do
c
Really 😅 I didn't know it actually helped anyone... The only reason I use RBuilder.() is for lambdas and for things that are so small that they don't impact performance (React cannot optimize renders for them). For anything sizeable you should definitely use functional components—but for minuscule functions I found it painful to declare the props interface etc.
👍 2
a
Also @Nikola Milovic feel free to join #react
n
@andylamax oh nice, forgot to check for that, thanks