1

I have a table of many rows which I'm passing props into. If the returned props are an empty string "" I don't want to render that row

    <Table.Body>

      <Table.Row>
        <Table.Cell>Producer</Table.Cell>
        <Table.Cell>{props.producer}</Table.Cell>
      </Table.Row>

      <Table.Row>
        <Table.Cell>Country</Table.Cell>
        <Table.Cell>{props.country}</Table.Cell>
      </Table.Row>

      <Table.Row>
        <Table.Cell>Region</Table.Cell>
        <Table.Cell>{props.region}</Table.Cell>
      </Table.Row>

      <Table.Row>    
        <Table.Cell>Subregion</Table.Cell>
        <Table.Cell>{props.subregion}</Table.Cell>
      </Table.Row>

    </Table.Body>

and where it gets rendered:

render() {
return (
//  <Container>
 <Grid>

    {this.state.wines.length ? (
          <List>
            {this.state.wines.map(wine => (
              <Grid>
               <DataWine header={wine.Wine} producer={wine.Producer} country={wine.Country} region={wine.Region} subregion={wine.Subregion}/>

              </Grid>
            ))}

          </List>
        ) : (
          <h3>No Results to Display</h3>
        )}

So in this example, if the JSON returns "" for Subregion, I don't want the row that says Subregion: " " to render. Thanks in advance!

3
  • {props.subregions !== "" ? <your_table_row/> : null} Commented Mar 6, 2019 at 5:26
  • It's unclear what you're asking for. Commented Mar 6, 2019 at 5:26
  • show your full DataWine component code or render method .? Commented Mar 6, 2019 at 5:29

1 Answer 1

4

I'm not pretty sure what you're asking for. But I'm pretty sure you just need to use && operator like:

{
  props.region &&
  <Table.Row>
    <Table.Cell>Region</Table.Cell>
    <Table.Cell>{props.region}</Table.Cell>
  </Table.Row>
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.