๋ฐ์ํ React32 [React] map ํจ์ ์ ์ฉ์ key props๋ฅผ ๋ถ์ฌํ๋ ์ด์ React์์ map ํจ์๋ฅผ ์ฌ์ฉํ ๋ ๋ ๋๋ง์ ๋ฌธ์ ๊ฐ ์์ง๋ง console ์ฐฝ์ ์ด๋ ๊ฒ ๋ฐ ๋๊ฐ ์๋ค. mappingํ๋ ๊ณผ์ ์์ ๋ฐฐ์ด์ ๊ฐ ์์๋ง๋ค ๊ณ ์ ํ key ๊ฐ์ ์ง์ ํด์ค ์ ์๋๋ฐ, ๊ทธ๊ฒ์ ์๋ตํ๋ฉด ์ ๋ฐ ์ค๋ฅ๊ฐ ๋ฌ๋ค! ๊ทธ๋์ โญ list ๋ด์ ๊ฐ child์๋ ๊ณ ์ ํ key ๊ฐ์ด ์์ด์ผํ๋ค. โญ ๐ฅ์ key ๊ฐ์ ์ค์ผํ ๊น? React๋ ๋ ๋๋ง ํ ๋ ๊ธฐ์กด ๋ฐฐ์ด๊ณผ ์๋ก์ด ๋ฐฐ์ด์ ๋น๊ตํด์ ๋ณ๊ฒฝ๋ ๋ถ๋ถ๋ง ๋ค์ ๋ ๋๋งํ๋ค. ๋ฐ๋ผ์ ์์๊ฐ ๋ณ๊ฒฝ๋์์๋ ๋ ๋น ๋ฅด๊ณ ํจ์จ์ ์ผ๋ก ๋ ๋๋ง ํ๊ธฐ ์ํด ์์ ๊ณ ์ ์ key ๊ฐ์ ์ค๋ค. ์ฐธ๊ณ ์ฌ์ดํธ โถ ๋ฆฌ์คํธ์ Key - React 2021. 11. 18. HTML, CSS ์ฝ๋๋ฅผ React๋ก ๋ณํํ ๋ ์ฃผ์ํ ์ ๐ณ ๊ฐ ์ฌ๋ฌ๊ฐ ์์ ๋ , ํ๊ทธ๋ก ์ ์ฒด ์ฝ๋๋ฅผ ๊ฐ์ธ์ค ๊ฒ! ex) import React from 'react'; class Login extends React.Component { return ( ์๋ ํ์ธ์ ์๋ ํ๊ณ์ธ์ ); } ๐ณ Self Closing Tag ๊ผญ ๋ซ์ ์ค ๊ฒ! , , , , , ์ ๋ซ์ผ๋ฉด ์ค๋ฅ ๋ ์ ๐ณ ์ง ๋ง๋์ง ํ์ธ ํ ๊ฒ! ๋ณธ์ธ์ ์ง ์๋ง์์ ํ์ฐธ ์ฝ์งํ์ใ ๐ณ import ๊ฒฝ๋ก ํ์ธ ํ ๊ฒ! CSS ํ์ผ์ด๋ img ํ์ผ ๊ฒฝ๋ก ์ค์ ์๋ชปํ๋ฉด ์ ์ฉ์ด ์๋ผ์ใ ใ ... 2021. 11. 17. [React] e.preventDefault(); ๐ช ์์ ์ ์ฝ๋ writeComment = e => { this.setState({ comment: e.target.value, }); }; addComment = e => { โญ๏ธ e.preventDefault(); const { commentList, comment } = this.state; this.setState({ commentList: [ ...commentList, { id: commentList.length + 1, userName: 'zzz_yk', content: comment, }, ], comment: '', }); }; enterKey = e => { if (e.key === 'Enter') { this.addComment(); } }; ๊ฒ์ ์ด๋ ๊ฒ ํ๊ณ ๋๊ธ์ ์ฐ๊ณ Enter.. 2021. 11. 16. [React] Each child in a list should have a unique key prop. ๋ฆฌ์กํธ๋ฅผ ๊ฐ๋ฐํ๋ฉด์ ํ๋ฒ์ฏค์ ๋ณด์ จ์ ๊ฒฝ๊ณ ๋ฉ์ธ์ง... ๋ผ๊ณ ํ๋ค๐ฅ map ํจ์์ ๋ํ ์ดํด๊ฐ ๋ถ์กฑํ์๋(์์งํ ์ง๊ธ๋ ๋ถ์กฑํจใ ใ ) ๋ฐฐ์ด๊ฑธ ์ ์ฉํด๋ณด๋๋ผ ์ด์ฌํ ์ฝ์งํ๊ณ ์์์.. ๐ช key ๊ฐ์ ์ฃผ์ง ์์ Comment.js import React from 'react'; import './Comment.scss'; class Comment extends React.Component { render() { const { commentList } = this.props; return ( {commentList.map(comment => { return ( // โญ๏ธ key ๊ฐ์ด ์์!! {comment.userName} {comment.content} ); })} ); } } export default Co.. 2021. 11. 16. [React] Invalid DOM property `class`. Did you mean `className`? React์์ className์ผ๋ก ์จ์ผํ๋๋ฐ class๋ก ํ๋ฉด ์ ๋ฐ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค. ์์ข์ ์์ ๐๐ป ์ข์ ์์ ๐๐ป 2021. 11. 16. ์ฃผ์ ์ฌ์ฉ๋ฒ ๐ฅ React ์ฝ๋ ์ฃผ์ ํ ์ค ์ฃผ์ : // ์ฌ๋ฌ ์ค ์ฃผ์ : /* */ Javascript์ ๋์ผํจ! // ํ ์ค ์ฃผ์ componentDidMount() { // console.log("hello world"); return; }; // ์ฌ๋ฌ ์ค ์ฃผ์ componentDidMount() { /* console.log("hello world"); return; */ }; 2021. 11. 16. ์ด์ 1 2 3 4 5 6 ๋ค์ ๋ฐ์ํ