Skip to content

Instantly share code, notes, and snippets.

@flemdizzle
Created February 17, 2018 22:05
Show Gist options
  • Save flemdizzle/0bcbe8bf1570ae7e16f535a3f100b944 to your computer and use it in GitHub Desktop.
Save flemdizzle/0bcbe8bf1570ae7e16f535a3f100b944 to your computer and use it in GitHub Desktop.
validationPlaceholder() {
if (this.state.validation_error && this.state.validation_data.status === 'required') {
return 'REQUIRED';
}
},
toggleInput() {
if (this.props.edit) {
return (
<div>
<PodInput
placeholder={this.validationPlaceholder()}
/>
</div>
);
}
@jkeam
Copy link

jkeam commented Feb 17, 2018

I would probably rewrite as:

toggleInput() {
  const { validation_error, validation_data } = this.state;
  const placeholder = (validation_error && validation_data.status === 'required') ? 'REQUIRED' : '';
  return (
    <div>
      { this.props.edit &&
        <PodInput
          placeholder={placeholder}
        />
      }
    </div>
  );
}

@flemdizzle
Copy link
Author

Oh woah, mapping those variables to this.state is pretty sweet. That's definitely not something I have seen before.

I suppose in this context, given the ternary statement, returning an empty string is a totally valid return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment