Parsing a react.js template, and it gives errors on double quotes.
render() {
return (
<div style={{ height: '100%', width: '100%' }} />
);
}
It gives error: Expecting 'CLOSE_RAW_BLOCK', 'CLOSE', 'CLOSE_UNESCAPED', 'STRING', 'NUMBER', 'BOOLEAN', 'OPEN_SEXPR', ' CLOSE_SEXPR', 'ID', 'DATA', got 'INVALID'
In general, this is a piece of my template which is react.js file, so that double quotes are useful to react. In this case, how would I parse that?
so the situation is that when you use double quotes in the plop template file it throws an error when you try to generate from that template?
@amwmedia yes, that's the case.
more detail: it complaints this:
...e={{{ height: '100%', width: '100%' }}}
-----------------------^
the problem here is the {{ }} handlebars is trying to process this when you really want React to process it. I'd be interested to hear how @mxstbr solved this on his react-boilerplace project. I've solved this for angular projects using a helper that goes something like this...
plop.addHelper('ng', text => `{{ ${text} }}`);
then in your template you would use it like...
render() {
return (
<div style={{ ng "height: '100%', width: '100%'" }} />
);
}
it's a bit of a hack, but it does get the job done.
@amwmedia yea, I have thought that solution, and thought that there might be a better solution. But I guess I will just use a helper for now.
I'll post here if I think of something better. maybe someone out there will come up with a better solution. I think the helper might be fine if it were named something better... maybe like escape?
We don't have that issue as we don't have templates with much JSX in it, sorry!