React Hook "useState" is called in function Error 😭

λ°•ν˜„μƒ(HyunSang Park)Β·2020λ…„ 9μ›” 27일
0

Error-S

λͺ©λ‘ 보기
1/1
post-thumbnail
post-custom-banner

μ•ˆλ…•ν•˜μ„Έμš”, TypeScritp와 Reactλ₯Ό μ΄μš©ν•œ WebRTC κ°œλ°œμ„ ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.
ν”„λ‘œμ νŠΈ 도쀑 μ•„λž˜μ™€ 같은 였λ₯˜ 사항이 λ°œμƒλ˜μ–΄μ„œ 뒀적뒀적 μ°Ύμ•„λ³Έ κ²°κ³Ό μž…λ‹ˆλ‹€.

였λ₯˜ λ‚΄μš© 😭

Error

μœ„ ν™”λ©΄μ—μ„œ 보면 React Hook "useState", "useEffect"에 λŒ€ν•œ React function component에 λŒ€ν•œ 였λ₯˜κ°€ μžˆμ–΄μ„œ κ°œλ°œμžλ“€μ˜ μ‹  Stackoverflowλ₯Ό ν†΅ν•΄μ„œ ν•΄κ²° ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

import React, { useState, useEffect} from "react";
import RTCVideo from '../Components/RTCVideo';


const rtc = () => {
  const [localStream, setLocalStream] = useState<MediaStream>();
  
  useEffect(()=>{
    navigator.mediaDevices.getUserMedia({video: true})
    .then(stream=>{
      setLocalStream(stream);
    })
  },[]);

  return (

    <div>
      <RTCVideo
        mediaStream = {localStream}
      />
    </div>
  );
};

export default rtc;

μœ„ μ½”λ“œμ—μ„œ 였λ₯˜κ°€ μžˆμŠ΅λ‹ˆλ‹€. const rtc = () =>에 λŒ€ν•΄μ„œ 였λ₯˜κ°€ μžˆμŠ΅λ‹ˆλ‹€. μ†Œλ¬Έμžμ™€ λŒ€λ¬Έμžλ‘œ μ»΄ν¬λ„ŒνŠΈ 이름을 ν•˜λ©΄ 쒋을 것 κ°™λ‹€κ³  λ‚˜μ™€ μžˆμŠ΅λ‹ˆλ‹€.

ν•΄κ²°λ°©μ•ˆ 🀩

Stackoverflow

μœ„μ— λ‚΄μš©μ—μ„œ 보닀 싢이 μ†Œλ¬Έμžλ‘œ μ»΄ν¬λ„ŒνŠΈ 이름을 μ‚¬μš©ν•˜μ§€ 말고 λŒ€λ¬Έμžλ‘œ μ»΄ν¬λ„ŒνŠΈλ₯Ό 짓지 말고 λŒ€λ¬Έμžμ™€ μ†Œλ¬Έμžλ₯Ό μ‚¬μš©ν•˜μ—¬μ„œ 해결을 ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

ν•΄κ²° μ™„λ£Œ πŸ’š

import React, { useState, useEffect} from "react";
import RTCVideo from '../Components/RTCVideo';


const RTC = () => {
  const [localStream, setLocalStream] = useState<MediaStream>();
  
  useEffect(()=>{
    navigator.mediaDevices.getUserMedia({video: true})
    .then(stream=>{
      setLocalStream(stream);
    })
  },[]);

  return (
    <div>
      <RTCVideo
        mediaStream = {localStream}
      />
    </div>
  );
};

export default RTC;

μœ„μ™€ 같이 λŒ€λ¬Έμžμ™€ μ†Œλ¬Έμžλ₯Ό μ΄μš©ν•΄μ„œ λ§Œλ“€κ±°λ‚˜ μ €μ²˜λŸΌ λŒ€λ¬Έμžλ‘œ λ§Œλ“€λ©΄ λ©λ‹ˆλ‹€!
그러면 μœ„μ™€ 같이 ν•΄κ²°ν•˜λ©΄ λ©λ‹ˆλ‹€ 🀩

profile
πŸ§‘πŸ»β€πŸ’» λ‹€μ–‘ν•œ μ†Œν”„νŠΈμ›¨μ–΄λ₯Ό κ°œλ°œν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€
post-custom-banner

0개의 λŒ“κΈ€