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 using an object? #82

Open
angelogulina opened this issue Nov 6, 2017 · 2 comments
Open

What about using an object? #82

angelogulina opened this issue Nov 6, 2017 · 2 comments

Comments

@angelogulina
Copy link

angelogulina commented Nov 6, 2017

Given this: https://github.com/vasanthk/react-bits/blob/master/patterns/18.conditionals-in-jsx.md
What about something like this:

const sampleComponent = () => {
  const basicCondition = flag && flag2 && !flag3;
  const obj = {
    'flag4': 'Blah',
    'flag5: 'Meh'
  };
  if (basicCondition) {
    return <p>{obj[flagName] || Herp}</p>
  }
  return <p>Derp</p>
};
@cytrowski
Copy link

cytrowski commented Nov 12, 2017

@angelogulina nice :D

Going further:

const sampleComponent = () => {
  const basicCondition = flag && flag2 && !flag3
  const obj = {
    'flag4': 'Blah',
    'flag5: 'Meh'
  }

  return <p>{basicCondition ? obj[flagName] || Herp : Derp}</p>
}

However I prefer using cond from lodash in such a case ;)

@angelogulina
Copy link
Author

@cytrowski, honestly I didn't think about cond.
Good idea, thanks!

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

2 participants