4 ms·
While I agree with your point, your example of React literally adds a DSL that requires a pre-compilation step. It's not required[0], I get that, but it's stil
by reificator 8y ago
While I agree with your point, your example of React literally adds a DSL that requires a pre-compilation step. It's not required[0], I get that, but it's still a new language.
[0]: It may not be required, but it was created for a reason....
- pests 8y agoI don't mind a pre-compilation step as I'm already doing it in my projects and a lot of the community is as well. There are other templating systems you can use in React if you don't like JSX. I've seen one codebase use direct calls to ReactDOM.createElement and there is a new hotness (which I can't think of the name of now) that replaces JSX with template literals, something like: function NamePetList(props) { return html` <div> Hello <b>${props.name}</b>! <ul> ${props.pets.map(pet => html` <li ${...pet.props}>${pet.name}</li>` } </ul> </div> ` } which I really like. The library parses the strings to figure out which elements to create. Flow control and variables are just normal template literal arguments.
- sophiebits 8y agoYou're likely thinking of https://github.com/developit/htm https://github.com/developit/htm.
- pests 8y agoOh yes! Thank you.
- reificator 8y agoI get the pros and cons of jsx/htm (and hyperhtml/lithtml) just fine. I'm just saying that bringing up React as an example of a framework that should not be treated as a new language is not the best possible example, since it does literally come with a new language.
- dakom 8y agoJSX is not only not required, it's sugar that breaks referential transparency: https://medium.com/@david.chambers/jsx-violates-referential-transparency-83261aa2c2b2 https://medium.com/@david.chambers/jsx-violates-referential-... Personally I still use it, but I think it's fair to say that as much as JSX was created for a reason, it's made optional for a reason too.
- jakelazaroff 8y agoJSX doesn't violate referential transparency. A component either is referentially transparent, or it isn't; nothing about how it's invoked changes that. Put another way: React calls your components, not you. You pass the component function itself to React.createElement, not its result.
- dakom 8y ago> You pass the component function itself to React.createElement, not its result. JSX prevents you from being able to do this directly. For example, <() => "hello" /> is illegal.
- deleted 8y ago[deleted]