Support for JSX like syntax (as in TypeScript) #2529
Replies: 8 comments
-
I'd think that there would be much better ways of designing such APIs so that they play well with C#. The team has expressed several times that they're not interested in embedding data formats like XML or JSON directly into the language and I can't imagine that doing so but specifically targeted as a single UI framework would gain much traction. |
Beta Was this translation helpful? Give feedback.
-
If you want to take out the Razor from Blazor then you might as well not even use ASP.NET anymore. The biggest advantage of Blazor is never needing to write JS interop ever again. |
Beta Was this translation helpful? Give feedback.
-
Nothing's preventing you from using React if you prefer it. I actually prefer the Razor way of doing things, because it's much cleaner, and provides a more explicit separation between logic and presentation. |
Beta Was this translation helpful? Give feedback.
-
I have no clue what the |
Beta Was this translation helpful? Give feedback.
-
@johnkellyoxford It's Alt + numpad 0, 1, 6, 7, on Windows, but only if you have a numpad. |
Beta Was this translation helpful? Give feedback.
-
Honestly @johnkellyoxford, how on earth didn't you know that? 😉 |
Beta Was this translation helpful? Give feedback.
-
you can use Razor syntax with Blazor : https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be great to have support for JSX like syntax in C#, similar to
https://www.typescriptlang.org/docs/handbook/jsx.html. Also see https://reactjs.org/docs/introducing-jsx.html.
Background
I have some experience in writing React applications with TypScript. The JSX syntax makes it very comfortable to write HTML like syntax in TypeScript. In TypeScript you can write something like:
In JavaScript this becomes somethink like
The function
createElement
is described at https://reactjs.org/docs/react-api.html#createelement.In .NET there is Blazor now, which has a lot of parallels to React in my opinion. I like the idea of Blazor very much. However, I do not like how Components are declared by using the Razor syntax for different reasons.
Razor code is C# embedded into HTML. It is transformed to C# and wrapped into a class by a tool outside of the C# compiler. Therefore you cannot directly code against this class. You cannot use it, as you can use other classes in C#. A Blazor component does not seem to be a first class citizen as other classes. Thus you can only use und write Blazor components in a specific way. This is a general problem with Razor, which is visible in VS 2017 for example. You cannot search for references within a Razor view, if the view is not open. With a JSX like syntax this would not be a problem, because it would be part of the C# compiler, in my opinion.
JSX is HTML like code embedded into JS. Therefore you still have the full power of the language. The classes, that you are writing, can be used as any other classes as well. This is a huge difference between the Razor/Blazor and the JSX way to me.
Proposal
It would be nice if we had something similar to JSX in C#.
For example, if I would write this in C#
this could become something like
You should also be able to use classes methods like tags in the syntax:
and
The method
CreateElement
could be provided by different approaches. For exampleusing static Microsoft.Blazor.Component
This should be as flexible as possible, to support different scenarios.
This could be used as an alternative to Razor in Blazor or in other projects. I think it would enable a lot of different things for web development.
Beta Was this translation helpful? Give feedback.
All reactions