5 ms·
Speaking of mental models, "basically templates" is the wrong mental model for JSX. JSX is syntactic sugar for the React.createElement() function. Writing some
by rejschaap 7y ago
Speaking of mental models, "basically templates" is the wrong mental model for JSX. JSX is syntactic sugar for the React.createElement() function. Writing some components using this function directly will lead to a much better understanding than treating it as templating.
- mewpmewp2 7y agoI treat them as templates also in my mind. Don't see anything wrong with that. In which scenario do you think it doesn't work out well? You could also argue that any template is syntactic sugar for whatever is happening behind the hoods. Also if you do not treat it as a template, I'm concerned you will do something very hacky, unreadable and unmaintainable.
- nicoburns 7y agoI'd argue that not only is JSX "like templates", it actually is a template. I know what the syntax sugar compiles down to, and I'm very appreciative of the benefits over traditional string-based templates. But for me the fundamental property of template is an easy way to interpolate data into a rendering structure, and JSX definitely is that. Perhaps you have a more restrictive idea of what constitutes a template?