반응형
react 실행하기
// 리액트 새로운 프로젝트 생성
create-react-app .
// 부트스트랩 설치
npm i bootstrap
React 에 WebCam 띄우기
import React, { useEffect, useRef } from 'react'
import 'bootstrap/dist/css/bootstrap.min.css'
function App(){
let videoRef = useRef(null)
//사용자 웹캠에 접근
const getUserCamera = () =>{
navigator.mediaDevices.getUserMedia({
video:true
})
.then((stream) => {
//비디오 tag에 stream 추가
let video = videoRef.current
video.srcObject = stream
video.play()
})
.catch((error) => {
console.log(error)
})
}
useEffect(() => {
getUserCamera()
},[videoRef])
return(
<div className='container'>
<h1>selfie App in React.js</h1>
hello world
<video className='container' ref={videoRef}></video>
</div>
)
}
export default App
useEffect
Using the Effect Hook – React
A JavaScript library for building user interfaces
reactjs.org
class 없이도 state나 다른 리액트 기능을 사용할 수 있는 것??
useRef
Hooks API Reference – React
A JavaScript library for building user interfaces
reactjs.org
가변값을 가지는 '상자' 같은 역할
리액트에 대한 이해가 부족한 상태에서 코드를 짜려고 하니깐 문제가 많이 발생하는 것 같다.
우선 리액트에서의 Hook이라는 개념을 정확히 이해하는게 중요한 것 같다
반응형
'study' 카테고리의 다른 글
| [JavaScript]Parsing error : Invalid shorthand property initializer 오류해결 (0) | 2022.04.28 |
|---|---|
| [python] UDP 클라이언트와 서버통신 (0) | 2022.04.04 |
| 디지털 컴퓨터(Digitial Computer) (0) | 2022.03.29 |
| DFS와 BFS 비교해보기 (0) | 2022.03.15 |
| no module named numpy pycharm[오류해결] (0) | 2021.12.07 |