รายละเอียดสำหรับเรียนรู้ React ปี 2020-2023 โดยโค้ชพล ดูหลักสูตรได้ที่ https://www.nextflow.in.th/react-training
เป็นรูปแบบการเขียนเชิง Object-Oriented Programing ซึ่งสำหรับหลายๆ คนอาจจะชอบแบบ Function Component ก็สามารถเลือกใช้ได้ แต่ปัจจุบันก็จะเป็นแบบ Function หมดแล้ว
โดยส่วนประกอบพื้นฐานของ Class Component คือ
render()
ที่คืนค่าเป็น JSXclass App extends React.Component {
render() {
return (
<div>
</div>
)
}
}
<script type="text/babel">
const Food = ({name}) => <h2>{name}</h2>;
class App extends React.Component {
render() {
return (
<div>
<Food name="Tom Yam Goong"/>
<Food name ="Khao Pad Sapparod"/>
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById("root")
);
</script>