I ran into this error recently while trying conditional rendering, here hoping if anyone could actually explain this behavior, here’s the code:
renderDeleteColumn = (user, movie, onDelete) => {
if (user && user.isAdmin) {
return (
<td>
<button
onClick={() => onDelete(movie)}
className="btn btn-danger btn-sm"
>
Delete
</button>
</td>
);
}
};
render() {
const { movies, onDelete, user } = this.props;
return (
<tbody>
{movies.map(movie => (
<tr key={movie._id}>
<td>{movie.genre.name}</td>
{() => this.renderDeleteColumn(user, movie, onDelete)}
</tr>
))}
</tbody>
)
}
So basically I am trying to render the column of a table based on if the user is logged in and is an admin, but my method is not working as expected.
Just to be clear, I know I can use use inline logical && operator to render this condition or the ternary operator, but I am curious as way a method would not work?