wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

conditional props #173

Closed PierBover closed 8 years ago

PierBover commented 8 years ago

I'm trying to figure out how to pass conditional props using rt-props but I'm getting the error RTCodeError: Unexpected token ..

The docs say:

The expected value of this attribute is an expression returning an object.

So I tried:

<div rt-props="{this.state.isEditing ? {selected:this.state.something.id} : {}}">

// also just in case
<div rt-props="{this.state.isEditing ? {selected:this.state.something.id} : null}">
<div rt-props="{this.state.isEditing ? {selected:{this.state.something.id}} : {}">

Is it possible to use a ternary expression in rt-props? What is the correct form?

nippur72 commented 8 years ago

special attributes like rt-props and rt-if don't need to be escaped with { and } because it's known that their argument is a javascript expression. So it's just

<div rt-props="this.state.isEditing ? {selected:this.state.something.id} : {}" >
PierBover commented 8 years ago

Oh right, so of course if I escape this is a malformed object.

Thanks @nippur72 !