4 ms·
Do Vue templates play nicely with Typescript? That's something I love about JSX -- "it's just JavaScript" is an incredibly sublime feature. I know you can use J
by ng12 9y ago
Do Vue templates play nicely with Typescript? That's something I love about JSX -- "it's just JavaScript" is an incredibly sublime feature. I know you can use JSX with Vue but I'm skeptical since it's a first-order feature with React.
- KitDuncan 9y agoSince October (I think) vue single file components work flawlessly with typescript. Can't speak for jsx though.
- tomonl 9y agoIt works in the <script lang="ts"> part of your .vue file, but not the <template> part.
- ng12 9y agoAh, that's a bummer. Vue Templates seem wildly regressive to me -- I can't fathom going back to stringly-typed Handlebars wrangling after using JSX/TSX. After looking into this further it seems like Vue Templates also differentiate between values and components. In React I often write components which can take in either: a good example is text which the consumer might want to format. You can easily write the component so that they pass in a string or a <span /> element. Vue has a lot of good ideas but the templates are almost a non-starter for me.
- faitswulff 9y agoYou don't have to use the templates, though. Define a render function and you can even use JSX in it: https://vuejs.org/v2/guide/render-function.html#JSX https://vuejs.org/v2/guide/render-function.html#JSX
- ng12 9y agoWhy wouldn't I just use React at that point? Same behavior, less complexity.
- CaveTech 9y agoYou can use slots to pass HTML or Components into child components. You can have vue render jsx or templates, but in practice you can make interactive components very simply using templates which are foundationally simpler and easier to grasp than JSX.
- ng12 9y agoHow so? In my mind templates and JSX are equally complex from a user standpoint. In fact I'd argue that JSX is simpler because you don't have to invent slots -- it's an obvious side effect of using JavaScript to generate your structure. Just reading about slot and slot-scope makes me think Vue's reputation for simplicity is overblown.
- ricardobeat 9y agoIt may seem "obvious" to you after being in the water with JSX for a while, but the free-style abstractions afforded by being 'just' JavaScript, like the one you mention, look incredibly complex for someone approaching an unknown codebase.
- petilon 9y agoI agree JSX is the best part of React. The second best part is dom diffing and incremental screen update. Obviously this second part is only useful if your application needs to update screens it previously rendered. In fact I'd argue that React is only useful if you need to incrementally update complex screens, because simple screens can be re-rendered completely and no one will know the difference. Very few applications need to incrementally update complex screens. If your application doesn't have this need you can use simpler technologies that don't have the same "Care and feed" requirements of React, such as UIBuilder: https://github.com/wisercoder/uibuilder https://github.com/wisercoder/uibuilder