How do people here feel about having directives in redwoodjs?
Personally I would love to have them, I have never been fan of doing ternary operator in react for doing stuff like conditional rendering. Directives is a nice abstraction layer for doing most common task like iterating over list or showing something based on the state.
Redwoodjs should ship with some directives helpers for more declarative ui. Why?
It’s easier for eyes to scan the code
Less code to write which it more elegant
Directives are more fun to use!
Another benefit I can see here is when there is an official redwood vscode extension in the future. We could provide snippets.
Secondly would be all developers coming out from angular, vue and svelte would appreciate having something like this. They will have much easier time to transition to react development!
I want to emphasis on “less code to write” maybe in the future there will be redwood styleguide like how to write idiomatic code in redwood fashion and I honestly believe helpers will play a bigger role.
IMHO, directives make the surface API more complex by adding another layer of indirection. It’s also another concept to learn to be proficient with redwood.
Instead, to express the views, I’d much rather use standard javascript constructs that people are already familiar with and use the full power of the language. For instance, in your code sample above, we could use an <Ingredient> or <CustomUL>.
I wanted to voice my opinion on directives, but I’ll let the core redwood team decide on this as I feel this is more “opinion” territory. I’m fine either way and will support their decision.
But to answer your question, I honestly prefer the first approach at it’s standard javascript. There’s no hidden fee or magical feature and I know 100% what’s happening with this code. It can also be rewritten like this:
Looking at the second snippet, this isn’t “just javascript/react code” anymore. There’s now an additional layer that needs to be understood and debugged, especially if rw-if was a “custom-made directive” rather than a built-in one.
(By the way, this isn’t important as I get your point, but I think these snippets are a bit different. Isn’t the first one showing one or the other message, while the second one always showing “Hi, there” and only optionally showing “AAHHH”?)
(By the way, this isn’t important as I get your point, but I think these snippets are a bit different. Isn’t the first one showing one or the other message, while the second one always showing “Hi, there” and only optionally showing “AAHHH”?)
The only difference is that one had <h1> and the other is a <p> instead. Plus a <div> wrapped around it but don’t worry it’s just a pseudo code to get my point across. So both examples are going to show the second argument hi, there! because of the state, is false to begin with.
Listen mate sometimes you have to think outside the box and being open-minded. I mean when jsx first came out a lot people didn’t like either, and also like the rewrite you are referring to. I hate to break this to you but it was not much of rewrite either. It was putting stuff in a single line instead of multi lines.
This is the line that keeps my brain processing too, yellAtPerson ? <h1>AAAHH</h1> : <span>hi, there!</span>