Mình thấy trong React có 2 loại, 1 là Element, 2 là Component. Vậy khi nào dùng element, khi nào dùng component nhỉ
Ví dụ trong ví dụ về todo của redux:
const Todo = ({ onClick, completed, text }) => (
<li
onClick={onClick}
style={{
textDecoration: completed ? 'line-through' : 'none'
}}
>
{text}
</li>
)
Todo.propTypes = {
onClick: PropTypes.func.isRequired,
completed: PropTypes.bool.isRequired,
text: PropTypes.string.isRequired
}
Mình thử chuyển nó sang component:
class Todo extends React.Component {
render() {
return (
<li
onClick={this.props.onClick}
style={{
textDecoration: this.props.completed
? 'line-through'
: 'none'
}}>
{this.props.text}
</li>
)
}
}
thì vẫn không thấy gì khác biệt