Giter Club home page Giter Club logo

Comments (8)

AlexGilleran avatar AlexGilleran commented on May 19, 2024

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.

AlexGilleran avatar AlexGilleran commented on May 19, 2024

(edited the comment above with a code fix and some other thoughts)

from jsx-control-statements.

mwiencek avatar mwiencek commented on May 19, 2024

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.

mwiencek avatar mwiencek commented on May 19, 2024

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.

AlexGilleran avatar AlexGilleran commented on May 19, 2024

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.

mwiencek avatar mwiencek commented on May 19, 2024

Wonderful, thanks! :)

from jsx-control-statements.

vkbansal avatar vkbansal commented on May 19, 2024

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.

AlexGilleran avatar AlexGilleran commented on May 19, 2024

Fixed by @texttechne in 3.0.0 :)

from jsx-control-statements.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.