Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Latest commit

 

History

History
24 lines (18 loc) · 597 Bytes

state-hook.md

File metadata and controls

24 lines (18 loc) · 597 Bytes

State Hook

State Hook คือ function ที่ทำให้เราใส่ state เข้าไปใน Function component ได้

import React, { useState } from "react";

function Counter() {
  const [counter, setCounter] = useState(0);
  return (
    <div>
      <h1>{counter}</h1>
      <button onClick={() => setCounter(counter + 1)}>Add</button>
      <button onClick={() => setCounter(counter - 1)}>Subtract</button>
    </div>
  );
}

export default Counter;




Table of Contents