Hacker News new | past | comments | ask | show | jobs | submit login

As I understand it, the problem is that template strings evaluate to strings, whereas JSX evaluates to function calls creating a data structure. So render would produce a string, React would have to parse it back out of the XML syntax to figure out the structure of the data hidden in the string, and then make function calls. That's expensive.

More importantly, how would you share data structures? `<Todos items=${someObject}>` would return a string with the string representation of someObject, but it wouldn't be the same object, have methods, etc.




You could probably use a tagged template literal that would return an object representation of the given string. Tagged template literals don't have to return strings; jsx`<Todos items=${someObject}>` could return an Element object, for example.


But the input is still a string? I think it's helpful to know that when you see JSX like this:

    <MixinComponent>
      <InnerComponent name='madeofpalk'/>
    </MixinComponent>

JSX will convert that into regular JS which will look like

    element('MixinComponent', {},
        element('InnerComponent', {name: 'madeofpalk'})
    )
Parsing that string during runtime to produce the above data structure isn't ideal.


Right, for sure. Template literals are not a good replacement for JSX.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: