Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

훈돌라

2024. 5. 27. 리액트 베이직 본문

카테고리 없음

2024. 5. 27. 리액트 베이직

훈돌라 2024. 5. 27. 21:00

 

카운트 앱 숫자 증가, 감소 시키기

function App() {
  const [count, setCount] = useState(0);

  const addCount = () => {
    setCount(count + 1);
  }

  const disCount =() => {
    setCount(count -1);
  }

  return (
    <>
      Count: {count}
      <div>
      <button onClick={addCount}>+</button>
      <button onClick={disCount}>-</button>
      </div>
    </>
  );
}

export default App;

 

 

다크모드

function App() {
  const [isDark, setIsDark] = useState(false);

  const changeMode = () => {
    setIsDark(!isDark);
  }

  return (
    <div style={{
      backgroundColor: isDark ? "black" : "white",
      color: isDark ? "white" : "black",
    }}>
      {isDark ? "다크모드" : "화이트모드"}
      <button onClick={changeMode}>change</button>
    </div>
  );
}

export default App;

 

 

폼 작성하기

function App() {
  const [inputValue, setInputValue] = useState("");
  const handleInputChange = (e) => {
    setInputValue(e.target.value)
  }

  const onSubmit = () => {
    alert(`당신이 입력한 값은 : " ${inputValue} ` )
    setInputValue("")
  }


  return (
    <div>
      <input onChange={handleInputChange} value={inputValue} type="text" placeholder="입력하세요">
      </input>
      <button onClick={onSubmit}>제출</button>
    </div>
  );
}

export default App;

 


 

import './App.css'
import React, { useState } from 'react'

const App = () => {
  const [count, setCount] = useState(0);

  const addCount = () => {
    setCount(count + 1);
  }

  const disCount = () => {
    setCount(count - 1);
  }

  const reMove = () => {
    setCount(0);
  }


  return (
    <>

    <div>

    Count : {count}

    </div>
    <div>
    <button onClick={addCount}>증가</button>
    <button onClick={disCount}>감소</button>
    </div>
    <button onClick={reMove}>리셋</button>
    </>
  )
}

export default App

 

 

베이직 과제 : 카운트 앱 증가, 감소, 리셋