Comments (8)
So the fact that there is an error in general makes sense, keep in mind that that desugars to:
foo ? {'foo'} : ''
Which isn't valid Javascript or JSX - it has to be either:
<If condition={foo}>
<span> {'foo'} </span>
</If>
or (this one I never do but I think it should work?)
<If condition={foo}>
'foo'
</If>
However, our transformer should really catch it and throw a nicer error message than that before it gets to Babel.
EIther that or I suppose it could check if the first child was a JSX Expression and strip out whatever's inside? Not sure if that leads to any further follow-on problems though.
from jsx-control-statements.
(edited the comment above with a code fix and some other thoughts)
from jsx-control-statements.
Ah, I see. I was sort of expecting it to desugar into something like {foo ? 'foo' : undefined}
.
I did try it without the {}
too, but it throws a Control statement must have a child!
error, with a bare string.
Another problem with removing the {}
is that I can't then use a function to return a string/array of elements/etc., which is my main use case.
from jsx-control-statements.
e.g. we wrap all of our user-visible strings for gettext lookup/extraction, so the previous example is more accurately:
<If condition={foo}>
{l('foo')}
</If>
from jsx-control-statements.
Ah yeah I see how that makes sense.
You can work around it for now by wrapping it in <span>
- I'll look into allowing {}
expressions in the next release.
from jsx-control-statements.
Wonderful, thanks! :)
from jsx-control-statements.
I too am facing a similar issue. I've put span
tags as work-around for now.
But ul > span > li
does not make any sense.
from jsx-control-statements.
Fixed by @texttechne in 3.0.0 :)
from jsx-control-statements.
Related Issues (20)
- The control statements don't narrow TypeScript types HOT 1
- TypeScript type for children is missing a render function HOT 1
- TChildren conflicts with ReactNode children HOT 2
- Why do we need ```transform-react-inline-elements``` plugin ?
- Switch-case style control statement HOT 2
- Problem with ./node_modules/tsx-control-statements/components.ts HOT 3
- Typo error HOT 1
- Support babel macros HOT 2
- conditional statements don't work unless wrapped in brackets. is this supposed to happen? HOT 1
- Not working with laravel-mix with webpack config
- Support babel-plugin-macros HOT 7
- Outdated npm link in description on GitHub project HOT 2
- Uncaught ReferenceError: For is not defined HOT 5
- Not working with create-react-app HOT 7
- If is not defined HOT 4
- App breaks if i try to directly access the url - With Error - Choose is not defined HOT 1
- React-Native:Installation-Guide HOT 2
- last published version is 3 years old HOT 2
- ESLint autofix HOT 2
- Undefined is not a function with new JSX transform with react 17 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsx-control-statements.