Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what about if-else ? #7

Open
sesky4 opened this issue Oct 20, 2016 · 4 comments
Open

what about if-else ? #7

sesky4 opened this issue Oct 20, 2016 · 4 comments

Comments

@sesky4
Copy link

sesky4 commented Oct 20, 2016

how to use 'else' condition? Thanks

@atticoos
Copy link
Owner

Currently you will need to do the opposite logic for an else:

renderIf(collection.length > 0)(
  <List collection={collection} />
)
renderIf(collection.length === 0)(
  <EmptyState />
)

"if-else" is a bit tricky in how this module works. If we were to implement it, I'd also want to implement "else if", which makes it even trickier

@sesky4
Copy link
Author

sesky4 commented Oct 21, 2016

thanks

@sundeepnarang
Copy link

@ajwhite I just made a temporary if-else version, as it helped us replace any ternary operators.

https://github.com/sundeepnarang/render-ifelse

will keep looking forward to your version with else-if support.

@atticoos
Copy link
Owner

atticoos commented Jun 5, 2017

I've put together a solution for this in #13

Basic usage:

<div>
  {renderIf.if(x === 1) (
    <span>Hello, 1</span>
  ).elseIf(x === 2) (
    <span>Hello, 2</span>
  ).elseIf(x === 3) (
    <span>Hello, 3</span>
  ).else(
    <span>Hello, {x}</span>
  ).evaluate()}
</div>

I welcome any feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants