3 ms·
Because you can pretty easily add a layer on top to make it nicer (like JSX). And it has the benefit of working with e.g. Typescript and give you type safety ou
by Oddskar 6y ago
Because you can pretty easily add a layer on top to make it nicer (like JSX). And it has the benefit of working with e.g. Typescript and give you type safety out of the box, unlike Frameworks that have their own template systems.
- skinkestek 6y agoAgree: Once one deliberately throws out support for all but JS-enabled browsers, HTML doesn't matter that much anymore and at that point tooling support like making it possible to work in TypeScript becomes a nice bonus. (Note however that while enjoy projects like these and also don't vilify most people who wrote JS-dependent websites, not even in my thoughts, I might think of those who write html with optional js-features as nicer people, more thoughtful/considerate and less childish ;-)
- strogonoff 6y agoThrowing out support for HTML-only browsers is not a prerequisite for authoring a reactive UI with JS. Using Next.js, react-static, or even plain ReactDOM’s renderToString() you can generate static HTML+CSS for your pages, which would then be hydrated and become interactive only in user agents with JS enabled. Authoring components with awareness of that, you can degrade gracefully while reaping the benefits of type checking, reusable components etc. at development stage.
- skinkestek 6y agoNo, but the moment you depend on Javascript being enabled in the client, why not get rid of as much of html as possible and use a sane language like TypeScript?
- strogonoff 6y agoYeah, upon rereading I see I wasn’t replying to what you meant.
- vagrantJin 6y agoHonest question, why jsx over html/js and why particularly Typescript?
- madeofpalk 6y agoWhy not Typescript? Using a typed languge is such a productivity boon.
- vagrantJin 6y agoThis a is an answer thats made for those "why you should use Typescript in 2021" medium articles that pop up on my feed ad nauseum. The word productive on its own is wholly meaningless without elaboration. What makes a typed language productive? Does the size of the project matter?, why is vanilla js not productive? Is it a lines of code metric? Is it a test suite efficiency metric? Is it a quality metric?
- Oddskar 6y agoProviding a thorough answer to your question would require a lengthy article. It's a bit much of an ask to have someone do this for you on HN. But very briefly I would say that these are the benefits as I see it: * Access to improved tooling. E.g. refactoring by renaming things is much easier to do without breaking things. Also auto-complete when using third party libraries is a huge benefit. * Some errors are automatically caught during build-time. E.g. checking the data used in a template lines up with what the component should be passing to that template. Without typescript one should probably verify this via unit tests. With TS these tests are superfluous. * Improved documentation. It's a lot easier to understand what the shapes are of data is that is being passed around in the application. It also provides the opportunity to define these in central locations (e.g. in the form of interfaces) which can then have additional documentation added to them. I think the benefits are not so much specific to TS as they are general benefits of using types and a typed ecosystem.
- SCLeo 6y agoI have not used Skruv, but from my experience with vanilla js (document.createElement('div')), hyperscript (h('div')), and jsx (<div/>), jsx is hoesntly much easier to write and to read.