コースの配列が空のときにテーブル要素を非表示にしたいとします。私は以下のコードがうまくいくことを期待していましたが、そうではありません。何か案は?問題のコードの行は次のとおりです。JSX、インライン三項演算子を使用して要素を非表示にしますか?
<table className="table" style={courses.length > 0 ? 'show' : 'display:none'}>
import React, {PropTypes} from 'react';
import CourseListRow from './CourseListRow';
const CourseList = ({courses, onDelete}) => {
return (
<table className="table" style={courses.length > 0 ? 'show' : 'display:none'}>
<thead>
<tr>
<th> </th>
<th>Title</th>
<th>Author</th>
<th>Category</th>
<th>Length</th>
</tr>
</thead>
<tbody>
{courses.map(course =>
<CourseListRow key={course.id} course={course} onDelete={onDelete}/>
)}
</tbody>
</table>
);
};
CourseList.propTypes = {
courses: PropTypes.array.isRequired
};
export default CourseList;
3進演算子を使用しないリアクションコンポーネントにインラインスタイルを適用するにはどうすればよいですか? – Hypaethral