Skip to content

Instantly share code, notes, and snippets.

@YounglanHong
Last active August 3, 2020 01:27
Show Gist options
  • Select an option

  • Save YounglanHong/ccc296dba0e5534cff3c6c7a88f2fea4 to your computer and use it in GitHub Desktop.

Select an option

Save YounglanHong/ccc296dba0e5534cff3c6c7a88f2fea4 to your computer and use it in GitHub Desktop.
// local state
let [results, setResults] = useState("");
// useEffect: mount, update -- 😈Infinite Loop
useEffect(() => {
axios
.get(`${API_URL}movie/${props.id}?api_key=${API_KEY}`)
.then((res) => {
console.log(res.data);
// 영화 id로 요청한 결과 로컬 state로 관리
setResults(res.data);
})
.catch((err) => {
console.log(err);
});
});
// useEffect: mount
useEffect(() => {
axios
.get(`${API_URL}movie/${props.id}?api_key=${API_KEY}`)
.then((res) => {
console.log(res.data);
// 영화 id로 요청한 결과 로컬 state로 관리
setResults(res.data);
})
.catch((err) => {
console.log(err);
});
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment