State
import './App.css'
import { useState } from 'react'
// root 컴포넌트
function App() {
const [state,setState] = useState(0);
console.log(state);
return (
<>
<h1>{state}</h1>
<button onClick={()=>{
setState(state+1);
}}></button>
</>
)
}
export default App
import './App.css'
import { useState } from 'react'
// root 컴포넌트
function App() {
const [count,setCount] = useState(0);
const [light,setLight] = useState("off");
console.log(count);
return (
<>
<h1>{light}</h1>
<button onClick={()=>{
if(light==="off"){setLight("on");}
else{setLight("off");}
}}></button>
<h1>{count}</h1>
<button onClick={()=>{
setCount(count+1);
}}></button>
</>
)
}
export default App
728x90
'DEVELOPE > 앱개발시작하기' 카테고리의 다른 글
[20240508] 앱개발 시작하기 #19 | 간단한 회원가입 1 (0) | 2024.05.08 |
---|---|
[20240508] 앱개발 시작하기 #18 | 간단한 회원가입 (0) | 2024.05.08 |
[20240507] 앱개발 시작하기 #16 | 이벤트 핸들링 (0) | 2024.05.07 |
[20240507] 앱개발 시작하기 #15 | props (0) | 2024.05.07 |
[20240507] 앱개발 시작하기 #14 | JSX 시작하기 (1) | 2024.05.07 |