You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Lenne231 "Nice" is not the reason to add the feature. Your proposal doesn't have any benefits over current solution, but will introduce more work for analyzers.
Uses the existing flexibility and doesn't require any new syntax. It also allows you to trivially move the function body somewhere else if the code gets unwieldy at some point.
In above snippet img is child. As expected. With children as render prop it is not. children as render prop becomes more and more popular. I think it is time to make it more native for jsx.
P.S. I don't insist that my or @Lenne231 solution is the best.
It doesn't look naturally. jsx is XML-like syntax.
Engineering/programming is about the correct solution for the problem, not a pleasing aesthetic.
And rener prop "as-is" is alike semi-solution IMHO.
It's an intended feature, just as JSX-children is just sugar for the children property. If you have a component that takes two sets of children, the correct engineering solution is to do:
<MyCompchildrenA={<div/>}childrenB={<div/>}/>
Whether it's aesthetically pleasing or not a secondary concern, that doesn't mean it's wrong to consider extending the syntax like you want. However, there's has to be a very strong use-case for it; that style of component you're using cannot be found anywhere in my projects. So in my case it would be entirely useless and that's a concern for adding a new syntax, how small/big is the actual the audience? Could it even encourage bad practices?
Please don't take my response as offensive, I'm simply trying to explain the problem from another perspective for your benefit. So I think if you want others to take this proposal seriously, you also need a convincing argument for why it's a really good idea for a wide audience that makes it worth the effort and practical/technical costs. Because that is not obvious to me.
IMHO this does not look like it would expand to the proposed:
<Foo>{(arg)=>("...")}</Foo>
To me, it looks like it would expand to:
const_Foo=Foo(arg);<_Foo>
...
</_Foo>
Which would make more logical sense. And might even somewhat make sense in some situations.
classMyComponentextendsHTMLElement{staticgetis(){return'my-component';}// ...}customElements.define(MyComponent.is,MyComponent);constwc=(WebComponent)=>WebComponent.is;constReactComponent=(props)=>{<div><wc(MyComponent)>
...
</wc></div>};// Or perhaps, if you want to be really strictconstReactComponent=(props)=>{<div><wc(MyComponent)>
...
</wc(MyComponent)></div>};
So on the chance that someone comes up with a better use case for something like that. I would definitely oppose co-opting that more logical usage of this syntax to instead refer to the proposed as-render prop expansion.
Activity
TrySound commentedon Jan 10, 2018
@Lenne231 "Nice" is not the reason to add the feature. Your proposal doesn't have any benefits over current solution, but will introduce more work for analyzers.
syranide commentedon Jan 12, 2018
The angle brackets should logically indicate that it creates and returns an element, but it actually returns a function.
kastigar commentedon Feb 2, 2018
And what about this? Lets take react-toggled example:
And replace it with:
Or above example:
It is similar to function declaration:
and can be read as "This element receives arguments x and y and can use them in children".
More examples:
syranide commentedon Feb 2, 2018
@kastigar What's wrong with:
Uses the existing flexibility and doesn't require any new syntax. It also allows you to trivially move the function body somewhere else if the code gets unwieldy at some point.
kastigar commentedon Feb 4, 2018
@syranide It doesn't look naturally.
jsxis XML-like syntax. And rener prop "as-is" is alike semi-solution IMHO.In above snippet
imgis child. As expected. Withchildrenas render prop it is not.childrenas render prop becomes more and more popular. I think it is time to make it more native for jsx.P.S. I don't insist that my or @Lenne231 solution is the best.
syranide commentedon Feb 4, 2018
Engineering/programming is about the correct solution for the problem, not a pleasing aesthetic.
It's an intended feature, just as JSX-children is just sugar for the
childrenproperty. If you have a component that takes two sets of children, the correct engineering solution is to do:Whether it's aesthetically pleasing or not a secondary concern, that doesn't mean it's wrong to consider extending the syntax like you want. However, there's has to be a very strong use-case for it; that style of component you're using cannot be found anywhere in my projects. So in my case it would be entirely useless and that's a concern for adding a new syntax, how small/big is the actual the audience? Could it even encourage bad practices?
Please don't take my response as offensive, I'm simply trying to explain the problem from another perspective for your benefit. So I think if you want others to take this proposal seriously, you also need a convincing argument for why it's a really good idea for a wide audience that makes it worth the effort and practical/technical costs. Because that is not obvious to me.
dantman commentedon Mar 4, 2018
I have a problem with the suggested expansion of:
IMHO this does not look like it would expand to the proposed:
To me, it looks like it would expand to:
Which would make more logical sense. And might even somewhat make sense in some situations.
So on the chance that someone comes up with a better use case for something like that. I would definitely oppose co-opting that more logical usage of this syntax to instead refer to the proposed as-render prop expansion.
Huxpro commentedon Feb 25, 2022
Personally I felt like we wouldn't pursue in this direction. Feel free to reopen if any one has a strong second opinion on this.