๋ชฉ๋ก๐ React (30)
๐ค ์์งlog ๐ค
SPA ( Single Page Application ) ์ต์ด ํ๋ฒ ํ์ด์ง ์ ์ฒด๋ฅผ ๋ก๋ฉํ ์ดํ ๋ถํฐ๋ ๋ฐ์ดํฐ๋ง ๋ณ๊ฒฝํ์ฌ ์ฌ์ฉํ ์ ์๋ ์น ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ปํ๋ค. ๐ฃ ๊ธฐ์กด ์น ํ์ด์ง ์์๋ ์ฌ์ฉ์๊ฐ ๋ค๋ฅธ ํ์ด์ง๋ก ์ด๋ํ ๋ ๋ง๋ค ์๋ก์ด HTML์ ๋ฐ์์ค๊ณ ํ์ด์ง๋ฅผ ๋ก๋ฉํ ๋ ๋ง๋ค ์๋ฒ์์ ๋ฆฌ์์ค๋ฅผ ์ ๋ฌ ๋ฐ์์ ํด์ํ ๋ค ํ๋ฉด์ ๋ณด์ฌ์คฌ๋ค. ๋ฐ๋ผ์ ์๋ฒ๊ฐ ํ ์ผ์ด ๋ง์๊ธฐ ๋๋ฌธ์, ์ฑ๋ฅ์์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์๋ค. ์๋ฒ ํธ๋ํฝ์ด ๋ง์ด ๋์ฌ ์๋ ์๊ณ ๋ง์ ์ฌ์ฉ์๊ฐ ๋ชฐ๋ฆฌ๋ฉด ๊ณผ๋ถํ๊ฐ ๊ฑธ๋ ค์ ์๋ฒ๊ฐ ๋ค์ด ๋๋ ๋ฑ์ ๋ฌธ์ ๊ฐ ๋ฐ์ ๊ฐ๋ฅํ๋ค. ์บ์ฑ๊ณผ ์์ถ์ ํตํด ์ด๋ ์ ๋ ๋ณด์ํ ์ ์์ง๋ง ์์ฆ ์ฒ๋ผ ์ฌ์ฉ์์์ ์ธํฐ๋์ ์ด ๋ง์ ํ์ด์ง์ ๊ฒฝ์ฐ ์ด ๋ฐฉ๋ฒ ๋ํ ํ๋ค์ด์ง๋ค. ๋ํ ํ๋ฉด ์ ํ์ด ํ์ํ ๋๋ง๋ค ์๋ก์ด HTML์ ..
useEffect(() => {},[]) useEffect 2๋ฒ์งธ ์ธ์์ ๋น ๋ฐฐ์ด์ ๋ฃ์ด์ฃผ๊ฒ ๋๋ฉด ์ปดํฌ๋ํธ๊ฐ ์ฒ์ ๋ ๋๋ง ๋ ๋๋ง ์คํ๋๋ค. ๐ useEffect ์ค๋ฅ๋ก 2๋ฒ ์คํ ๋ ๋ ๐ src/index.js์์ ํ๊ทธ๋ก ์ด ๊ฐ์ธ์ ธ์์ผ๋ฉด ๊ฐ๋ฐ๋ชจ๋์์ ๋ ๋ฒ์ฉ ๋ ๋๋ง๋๋ค. import React from 'react' import ReactDOM from 'react-dom/client' import App from './App' import reportWebVitals from './reportWebVitals' import './index.css' const root = ReactDOM.createRoot(document.getElementById('root')) root.render( โฌ ์ง์ฐ๊ธฐ , ..
๐ก ํผ์์ ๋ง๋ค์ ์๋ค๋ฉด ์ฌ๋ฌ๋ฒ ์ฐ์ตํด๋ณด๊ธฐ ๐ก import { useState, useRef } from 'react' import styled, { css } from 'styled-components' const Todo = () => { const [text, setText] = useState('') const [todoList, setTodoList] = useState([]) const nextId = useRef(1) const handleChange = (e) => { setText(e.target.value) } const handleSubmit = (e) => { e.preventDefault() // form ์์ submit ์ญํ ์ ํ๋ ๋ฒํผ์ ๋๋ ์ด๋ ์๋ก๊ณ ์นจ ๋์ง ์๊ฒ ํ๊ณ ์ถ์ ..
Naver ์ํ ๊ฒ์ ๐ฃ 1. Router.js ์์ฑ import { BrowserRouter, Routes, Route } from 'react-router-dom' import Main from './components/pages/Main' import Movie from './components/pages/Movie' import Book from './comp.. eun-jii.tistory.com Naver ์ฑ ๊ฒ์ Naver ์ํ ๊ฒ์ ๐ฃ 1. Router.js ์์ฑ import { BrowserRouter, Routes, Route } from 'react-router-dom' import Main from './components/pages/Main' import Movie from './..
๐ฃ 1. Router.js ์์ฑ import { BrowserRouter, Routes, Route } from 'react-router-dom' import { Login, Main, Signup } from './Components/Pages' const Router = () => { return ( . . ) } export default Router ๐ฃ 2. index.js export { default as Login } from './Login' export { default as Main } from './Main' export { default as Signup } from './Signup' ๐ฃ 2-1. App.js ์ Router โก import import Router from './..
Naver ์ํ ๊ฒ์ ๐ฃ 1. Router.js ์์ฑ import { BrowserRouter, Routes, Route } from 'react-router-dom' import Main from './components/pages/Main' import Movie from './components/pages/Movie' import Book from './comp.. eun-jii.tistory.com ๐ฃ 1. Router.js ์์ฑ import { BrowserRouter, Routes, Route } from 'react-router-dom' import Main from './components/pages/Main' import Movie from './components/pages/Movie'..
๐ฃ 1. Router.js ์์ฑ import { BrowserRouter, Routes, Route } from 'react-router-dom' import Main from './components/pages/Main' import Movie from './components/pages/Movie' import Book from './components/pages/Book' const Router = () => { return ( ) } export default Router ๐ฃ 2. Main.jsx import { Link } from 'react-router-dom' import styled from 'styled-components' const Main = () => { return ( ์ํ ๐ฌ..
๐ฃ 1. Modal Background CSS (๊ธฐ๋ณธ์ ์ธ) import styled from 'styled-components' const Modal = () => { return ( Modal ) } const Backdrop = styled.div` width: 100vw; height: 100vh; position: fixed; top: 0; left: 0; background: rgba(0, 0, 0, 0.7); ` const Container = styled.div` position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; min-width: 300px; border-radius: 4px; `..
๐ฃ 1. Bootstrap.jsx ์ปดํฌ๋ํธ ์์ฑ import Dropdown from './Dropdown' const Bootstrap = () => { return ( ) } export default Bootstrap ๐ฃ 2. Dropdown.jsx ์ปดํฌ๋ํธ ์์ฑ import { useEffect, useState, useRef } from 'react' import styled from 'styled-components' const Dropdown = () => { const [showList, setShowList] = useState(false) const btnEl = useRef(null) useEffect(() => { const onClick = (e) => { if (btnEl.cur..
๐ฃ 1. Bootstrap.jsx ์ปดํฌ๋ํธ ์์ฑ import Accordion from './Accordion' import { accordionData } from '../../datas/bootstrap' const Bootstrap = () => { return ( ) } // ์์ฝ๋์ธ์ปดํฌ๋ํธ๋ฅผ ๋ฐ์ดํฐ๋ง ๊ฐ์๋ผ์ฐ๋ฉด ์์ ๋ด์ฉ์ ๊ต์ฒดํ๋ฉด์ ์ฌํ์ฉ๊ฐ๋ฅ export default Bootstrap ๐ฃ 2. Accordion.jsx ์ปดํฌ๋ํธ ์์ฑ import { useState } from 'react' import styled from 'styled-components' import { ReactComponent as Arrow } from './arrow.svg' const Accordion = ({ ..