News for hackers. Stuff that matters.
Re:React has grown beyond its original promise and it's caus... by forgotusername6 on Friday February 09, 2024 @02:25AM (#39312342)
What's it missing?
Re:React has grown beyond its original promise and it's caus... by richeyryan on Friday February 09, 2024 @04:04AM (#39312922)
I suspect they want better condition handling. Because JavaScript lacks a useful conditional expression beyond ternary expressions, condition handling in JSX generally uses boolean operators or ternary expressions. Suppose the conditional logic is in any way complex. In that case, your choice is to use nested ternary expressions, which can be hard to read or to somehow break the condition out of the JSX using a helper function or separate component so you can use if statements in a regular function context. SolidJS added conditional helpers to its JSX flavour to address this issue[1]. The React team seems ideologically opposed to the idea as it presumably moves JSX away from using only JavaScript for handling logic.

[1]https://www.solidjs.com/docs/latest/api#show

Re:React has grown beyond its original promise and it's caus... by tauchunfall on Friday February 09, 2024 @08:56AM (#39314866)
>I suspect they want better condition handling. Because JavaScript lacks a useful conditional expression beyond ternary expressions, condition handling in JSX generally uses boolean operators or ternary expressions.

If a condition in JSX gets too complex I normally extract a component-level function and call it from the JSX part of the component.

Re:React has grown beyond its original promise and it's caus... by _betty_ on Friday February 09, 2024 @04:17AM (#39313007)
knowing both i used to be frustrated by jsx's lack of support for plain if and for loops like razor has (eg map and the weird && syntax we general end up with)

eg ``` <ul> @foreach(var item in list) { <li>@item.name</li> } </ul> ```

of course this idea goes against jsx's implementation (as it's just nested functions) and paradigm of being html in plain javascript rather than an interpreted templating language.

some of the differences i really like (like being able to assign compoents to variables, pretty sure razor doesn't have anything like that).

Re:React has grown beyond its original promise and it's caus... by javcasas on Friday February 09, 2024 @10:15AM (#39315584)
The thing about jsx is that I don't have to learn the special syntax and rules that govern the @foreach construct.

jsx map accepts a js function which should return a jsx element. Can I use...? If it works in js, yes.

Re:React has grown beyond its original promise and it's caus... by _betty_ on Friday February 09, 2024 @02:54PM (#39319682)
Foreach in razor is just c# too, so it's not a language thing it's more what it transpiles to.