been working with React for a few weeks and I'm trying to get conditional rendering to work. I'm working with a table with a few rows, where each row has a 'edit' and 'delete' button. On the 'Secured' column, where the values are false, I would like to have both buttons to not display. I have tried to render the buttons to be hidden and with some logic, the buttons would display if the props were not false. I'm using the ConfigComponent on another piece of code where I'm displaying all of the table values.
See table Below:
const ConfigComponent = (props) => {
console.log(props.secured)
if (props.secured !== true) {
return (
<tr>
<td>{props.configCategory}</td>
<td>{props.configValue}</td>
<td>{props.description}</td>
<td>{props.configTypeId}</td>
<td>{props.dataTypeId}</td>
<td>{props.secured}</td>
<td>{props.createdDate}</td>
<td>{props.modifiedDate}</td>
<td>{props.modifiedBy}</td>
<td>{props.id}</td>
<td><button type="button" class="btn btn-sm btn-primary" hidden={!props.secured} onClick={() => props.onClick(props.id)}>Edit</button></td>
<td><button type="button" class="btn btn-sm btn-danger" hidden={!props.secured} onClick={() => props.onDelete(props.id)}>Delete</button></td>
</tr>
)}
else {
return (
<tr>
<td>{props.configCategory}</td>
<td>{props.configValue}</td>
<td>{props.description}</td>
<td>{props.configTypeId}</td>
<td>{props.dataTypeId}</td>
<td>{props.secured}</td>
<td>{props.createdDate}</td>
<td>{props.modifiedDate}</td>
<td>{props.modifiedBy}</td>
<td>{props.id}</td>
</tr>
)}
}
render() {
let configList = this.state.configList
return (
<React.Fragment>
<h3 class="font-weight-bold py-3 mb-4">Config List</h3>
<table className="table">
<thead>
<tr>
<th>Config Category</th>
<th>Config Value</th>
<th>Description</th>
<th>ConfigTypeId</th>
<th>DataTypeId</th>
<th>Secured</th>
<th>Created Date</th>
<th>Modified Date</th>
<th>Modified By</th>
<th>ID</th>
</tr>
</thead>
<tbody>
{configList.map((config, i) => {
return (
<React.Fragment key={i}>
<ConfigComponent
key={config.id}
id={config.id}
configCategory={config.configCategory}
configValue={config.configValue}
description={config.description}
configTypeId={config.configTypeId}
dataTypeId={config.dataTypeId}
secured={(config.secured).toString()}
createdDate={moment(config.createdDate).format("YYYY-MM-DD")}
modifiedDate={moment(config.modifiedDate).format("YYYY-MM-DD")}
modifiedBy={config.modifiedBy}
onClick={this.editClick}
onDelete={this.deleteClick} />
</React.Fragment>
)
})}
</tbody>
</table>
</React.Fragment>
)
}