ตัวอย่างการใช้งาน React JS
ตัวอย่างการใช้งาน React JS
import React, { useState } from 'react';
function App() {
const [count, setCount] = useState(0);
return (
<div>
<h1>Count: {count}</h1>
<button onClick={() => setCount(count + 1)}>เพิ่ม</button>
<button onClick={() => setCount(count - 1)}>ลด</button>
</div>
);
}
export default App;
ในตัวอย่างข้างต้น เราใช้ React Hook ที่เรียกว่า useState
เพื่อจัดการค่าตัวแปร count
ซึ่งเป็นตัวนับในแอปพลิเคชัน React ของเรา
Last updated
Was this helpful?