๋ชฉ๋ก2022/02/18 (10)
whatisthis?
์ฐธ๊ณ - ์์ฃผ ์ฌ์ฉํ์ง ์๋๋ค. import { useState } from "react"; function App() { const [showing, setShowing] = useState(false); const onClick = () => { setShowing(prev => !prev); }; return ( {showing ? "Hide" : "Show"} ); } export default App; ์์ธํ ์ค๋ช ์ ์ด์ ์๋ตํ๊ฒ ์.. (๋จ์ useState๋ฅผ ์ด์ฉํ ๊ฒ) ์ด์ ์จ๊น ๋ฒํผ์ ๋ง๋ค์์ผ๋ ์จ๊ธธ ๋์(์ฃผ๋ก ๋ค๋ฅธ ์ปดํฌ๋ํธ๋ฅผ ์จ๊ธฐ๊ณ ๋ํ๋ธ๋ค)์ ๋ง๋ค์ด๋ณด์. function Hello() { return Hello; } ๋จ์ํ๊ฒ h1 jsx๋ฅผ ๋ฆฌํดํ๋ Hello ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ ํ func..
React. React JS - Effects (1) React JS State Props Effects App.js const [counter, setValue] = useState(); import { useState } from "react"; ์๋์ผ๋ก import๋ฌธ์ด ์๊ธด๋ค. ์ด์ ์ฒ๋ผ React.useState()๋ผ๊ณ ์ํ๊ณ ๊ทธ๋ฅ useState()๋ง ํ๋ฉด.. mywebproject.tistory.com ์ง๋ ํฌ์คํ ์ ๋ด์ฉ์ ์ด์ด์ ์งํ๋จ. ๐ useEffect useEffect๋ ๋๊ฐ์ argument๋ฅผ ๊ฐ์ง๋ ํจ์์ด๋ค. arg1 > effect: EffectCallback (ํ๋ฒ๋ง ์คํํ ์ฝ๋๋ฅผ ๋ด์ ์ฝ๋ฐฑ) arg2 > deps?DependencyList const [keyword, setKe..
React JS State Props Effects App.js const [counter, setValue] = useState(); import { useState } from "react"; ์๋์ผ๋ก import๋ฌธ์ด ์๊ธด๋ค. ์ด์ ์ฒ๋ผ React.useState()๋ผ๊ณ ์ํ๊ณ ๊ทธ๋ฅ useState()๋ง ํ๋ฉด ๋๋ค! ์ฌ๊ธฐ์ ์ด์ ์ ๋ฐฐ์ ๋๋๋ก onClickํจ์๋ฅผ ๋ง๋ค์ด ๋ฒํผ์ onClick prop์ ์ฐ๊ฒฐํด์ฃผ์. ๐ป App.js ์ ์ฒด์ฝ๋ import { useState } from "react"; function App() { const [counter, setValue] = useState(0); const onClick = () => setValue(prev => prev + 1); return ( ..
์ฐ์ , ๋ฒํผ์ ํด๋นํ๋ ์ปดํฌ๋ํธ๋ฅผ ๋ด์ Button.js๋ฅผ ๋ง๋ฌ >> ๊ฐ๊ฐ์ ์ปดํฌ๋ํธ๋ฅผ ํ๋์ jsํ์ผ๋ก ๋ฐ๋ก ๊ด๋ฆฌ! Button.js function Button({ text }) { return {text}; } export default Button; App.js ์์ - import Button - Button ์ฌ์ฉ App.js import Button from "./Button"; function App() { return ( Welcome back! ); } export default App; ** prop-types ํจํค์ง ์ค์น ๐ป ํฐ๋ฏธ๋์ฐฝ์ ์๋์ ๊ฐ์ด ์ ๋ ฅ npm i prop-types Button.js import PropTypes from "prop-types"; function Bu..
create-react-app ๊ฐ์ฅ ๋จผ์ ํ ๊ฒ์ node js์ ์ค์น์ด๋ค. Node. Node Js + NPM ์ด๋? Node.js๋ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ๋ธ๋ผ์ฐ์ ์ธ์ ๋ค๋ฅธ ํ๊ฒฝ์์๋ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ๋ฐํ์์ ๋๋ค. http์๋ฒ๊ฐ ๋ด์ฅ๋์ด ์๊ธฐ ๋๋ฌธ์ ๋ณดํต์ ์๋ฒ๋ก ๋ง์ด ์ฌ์ฉํฉ๋๋ค. ํ์ง๋ง ์์ฉ ํ๋ก๊ทธ๋จ์ ์คํ mywebproject.tistory.com node js ์ค์น + npm์ด๋ ๋ฌด์์ธ์ง์ ๋ํด ์ ํฌ์คํ ์ ์ ๋ฆฌํ์๋ค. node๊ฐ ์ ์ค์น๋์๋ค๋ฉด, cmd์ฐฝ์ ์ด์ด npx create-react-app (ํ๋ก์ ํธapp์ด๋ฆ)์ ์ ๋ ฅํ๋ค. npx create-react-app project ์ค์น๊ฐ ์๋ฃ๋์์ผ๋ฉด (Happy hacking!์ด๋ผ ๋ธ) ํด๋น ๋๋ ํฐ๋ฆฌ์ ๋ค์ด๊ฐ๋ณด์. ์์ ๊ฐ์ด package..
Node. Node JS ์๋ฒ ์์ฑํ๊ธฐ ์ฐ์ server.js ํ์ผ์ ๋ง๋ค๊ณ , ์๋ ์ฝ๋๋ฅผ ์์ฑํจ. server.js const http = require('http'); // ์๋ฒ๋ฅผ ๋ง๋๋ ๋ชจ๋ ๋ถ๋ฌ์ด // http ๋ชจ๋ ๋ด์ createServer ๋ฉ์๋ http.createServer((request, response) =>.. mywebproject.tistory.com ์ง๋ ํฌ์คํ ์์ server.js๋ฅผ ์์ฑ ํ cmd์ฐฝ์์ node server.js๊น์ง ์งํํ์๋ค. server.js const http = require('http'); // ์๋ฒ๋ฅผ ๋ง๋๋ ๋ชจ๋ ๋ถ๋ฌ์ด // http ๋ชจ๋ ๋ด์ createServer ๋ฉ์๋ http.createServer((request, response) =>..
์ฐ์ server.js ํ์ผ์ ๋ง๋ค๊ณ , ์๋ ์ฝ๋๋ฅผ ์์ฑํจ. server.js const http = require('http'); // ์๋ฒ๋ฅผ ๋ง๋๋ ๋ชจ๋ ๋ถ๋ฌ์ด // http ๋ชจ๋ ๋ด์ createServer ๋ฉ์๋ http.createServer((request, response) => { // ์๋ฒ ๋ง๋๋ createServer ๋ฉ์๋ console.log('server start!'); }).listen(8080); // 8080ํฌํธ์ ์ฐ๊ฒฐ(listen) Node.js๋ ๋ชจ๋ ์์คํ ์ ๊ตฌ์ถํ๊ณ ์์ต๋๋ค. ** ๋ชจ๋ = ํ์ํ ๊ฒ๋ง ๋ถ๋ฌ์ค๋ ๊ฒ http ์๋ฒ๊ฐ ํ์ํ๋ http ๋ชจ๋์ require ๋ฉ์๋๋ฅผ ํตํด์ ๋ถ๋ฌ์ http ๋ณ์์ ์ ์ฅํ์์ต๋๋ค. ์ ์๊ฐ์ ๋งํ๋ npm์ ํจํค์ง๊ฐ ์ด์ ๋น..
Node.js๋ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ๋ธ๋ผ์ฐ์ ์ธ์ ๋ค๋ฅธ ํ๊ฒฝ์์๋ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ๋ฐํ์์ ๋๋ค. http์๋ฒ๊ฐ ๋ด์ฅ๋์ด ์๊ธฐ ๋๋ฌธ์ ๋ณดํต์ ์๋ฒ๋ก ๋ง์ด ์ฌ์ฉํฉ๋๋ค. ํ์ง๋ง ์์ฉ ํ๋ก๊ทธ๋จ์ ์คํํ๋ ๋ฐ ์ธ ์๋ ์์ต๋๋ค. ์นํฉ, ๋ฐ๋ฒจ๊ณผ ๊ฐ์ ๋๊ตฌ๋ค๊ณผ ์ผ๋ ํธ๋ก ๊ฐ์ด ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ฐ์คํฌํ ํ๋ก๊ทธ๋จ์ ๋ง๋๋ ํ๋ ์์ํฌ๊ฐ ๋ชจ๋ Node.js๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋์๊ฐ๋๋ค. ํํ๋ค ์๊ฐํ๊ธฐ๋ก๋ ์๋ฒ๊ฐ ์์ฒญ ๋ณต์กํ๋ค๊ณ ์๊ฐํ์ง๋ง, Node.js์์๋ 10์ค๋ ์ ๋๋ ์ฝ๋๋ก ์๋ฒ๋ฅผ ๊ตฌ๋ํ ์ ์์ต๋๋ค. +) ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ๋ฒ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์, ๋ค๋ฅธ ์๋ฒ ์ธ์ด๋ฅผ ๋ฐฐ์ฐ์ง ์์๋ ๋ผ์ ๋ถ๋ด์ด ํจ์ฌ ๋ํฉ๋๋ค. ์ด์ฐจํผ ํด๋ผ์ด์ธํธ(์น ๋ธ๋ผ์ฐ์ ) ์์์๋ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ธ ์ ๋ฐ์ ์์ต๋๋ค. ๊ทธ๋ฐ๋ฐ ์๋ฒ ์ธ์ด๋ JSP๋ PHP, A..
PropTypes ๋ง์ฝ, ์ฐ๋ฆฌ๊ฐ fontSize์ ํด๋นํ๋ prop์ ๊ฐ์ number๋ก ์ฃผ์ง ์๊ณ text๋ก ์ฃผ๋ฉด ์ด๋ป๊ฒ ๋ ๊น? return ( ); function Btn({ text, fontSize }) { return ( {text} ); } React๋ ์ด๊ฒ์ ์ค๋ฅ๋ผ๊ณ ์๋ ค์ฃผ์ง ์๋๋ค. ์๋๋ฉด ๋ฌธ๋ฒ์ ์ผ๋ก๋ ํ๋ฆฐ ๊ฒ์ด ์์ผ๋ฏ๋ก. ๋ฐ๋ผ์, ์ฐ๋ฆฌ๋ propTyes๋ผ๋ ํจํค์ง๋ฅผ ๋ค์ด๋ฐ์์ ์ฌ์ฉํ ์ ์๋ค. propTyes๋ ์ปดํฌ๋ํธ๋ช .propTypes๋ผ๊ณ ํ์ฌ ๊ฐ์ฒด์ ํ์์ผ๋ก ์ปดํฌ๋ํธ์ prop๋ณ๋ก ํ์ ์ ์ง์ ํด์ค ์ ์๋ค. ์๋ฅผ ๋ค๋ฉด, Btn ์ปดํฌ๋ํธ์ text ์์ฑ์ string์ผ๋ก, fontSize ์์ฑ์ number๋ก ์ค์ ํด์ค๋ค. Btn.propTypes = { text: PropTypes.s..
React. React Js - props props๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ props = ๋ถ๋ชจ ์ปดํฌ๋ํธ๋ก๋ถํฐ ์์ ์ปดํฌ๋ํธ์๊ฒ ๋ฐ์ดํฐ๋ฅผ ์ ์กํ๋ ๋ฐฉ์. (๋ถ๋ชจ->์์) ๋ถ๋ชจ์ props๋ฅผ ์ฌ์ฉํ๋ฉด ์์ ์ปดํฌ๋ํธ(ํจ์)์ ์ธ์๋ก props ๊ฐ์ฒด๊ฐ ๋ค์ด๊ฐ๊ฒ ๋จ mywebproject.tistory.com ์ง๋ ํฌ์คํ ์ธ props์ ์์ ๋ฅผ ์ด์ด์ ์งํํจ. ์ง๋์๊ฐ์ ํ๋ ๊ฒ์ ๋ณต์ตํด๋ณด์. Btn ์ปดํฌ๋ํธ๋ฅผ ์ค์ ํ๋ App ์ปดํฌ๋ํธ์์ return ( ); ์์ ๊ฐ์ด text๋ผ๋ property๋ฅผ ์ฃผ๊ณ , (text ๋์ banana๋ผ๊ณ ์ด๋ฆ ๋ถ์ฌ๋ ok. ์ด๋ฆ์ ์๊ด X) function Btn({text}) { return ( {text} ); } Btn ์ปดํฌ๋ํธ์์ props๋ผ๋ ํ๋ผ๋ฏธํฐ(=๊ฐ์ฒด์) ์ text๋ฅผ..