[TIL/React] 2023/06/27
Layout.jsHome.js오늘의 삽질어제 예정한 대로, 오늘은 공식문서의 코드를 참고하여 스크롤 기능을 완성하는 것이 목표였다. 개별 컴포넌트에서 forwardRef를 사용하는 것은 큰 문제가 되지 않았다.분명 제대로 했는데, 맵핑 과정에서 footer가 화면 최하
Layout.js
import React, { useRef } from "react";
import { styled } from "styled-components";
const Header = styled.div`
background-color: #c07848;
display: flex;
width: 100%;
height: 10vh;
position: sticky;
top: 0;
z-index: 999;
justify-content: space-around;
`;
const LogoContainer = styled.div`
width: 100px;
background-color: gray;
display: flex;
justify-content: center;
align-items: center;
`;
const NavButtonContainer = styled.div`
display: flex;
align-items: center;
column-gap: 40px;
`;
const NavButton = styled.button``;
const HamburgerIconContainer = styled.div`
width: 100px;
background-color: gray;
display: flex;
justify-content: center;
align-items: center;
`;
const Content = styled.div`
height: 100vh;
overflow: auto;
`;
const Footer = styled.div`
background-color: gray;
display: flex;
height: 20vh;
width: 100%;
justify-content: space-around;
margin: 0 auto;
`;
const FooterTextContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
`;
const Layout = ({ children }) => {
const homeRef = useRef(null);
const addRef = useRef(null);
const recentRef = useRef(null);
const myRef = useRef(null);
const refs = [homeRef, addRef, recentRef, myRef];
const handleHomeClick = () => {
homeRef.current.scrollIntoView({ behavior: "smooth" });
};
const handleAddClick = () => {
addRef.current.scrollIntoView({ behavior: "smooth" });
};
const handleRecentClick = () => {
recentRef.current.scrollIntoView({ behavior: "smooth" });
};
const handleMyClick = () => {
myRef.current.scrollIntoView({ behavior: "smooth" });
};
return (
<div>
{/* header area */}
<Header>
{/* logo */}
<LogoContainer>
<p>로고 자리</p>
</LogoContainer>
{/* nav button */}
<NavButtonContainer>
<button onClick={handleHomeClick}>Home</button>
<button onClick={handleAddClick}>AddTask</button>
<button onClick={handleRecentClick}>RecentTodo</button>
<button onClick={handleMyClick}>MyTodo</button>
</NavButtonContainer>
{/* hamburger icon */}
<HamburgerIconContainer>
<p>햄버거</p>
</HamburgerIconContainer>
</Header>
{/* content area */}
{children.map((child, index) => (
<Content ref={refs[index]} key={index}>
{child}
</Content>
))}
{/* footer area */}
<Footer>
<FooterTextContainer>
<p>My task</p>
<p>Copyright © 2023 All rights reserved</p>
<p>Powered By SITE123 - Create your own website</p>
</FooterTextContainer>
<NavButtonContainer>
<button onClick={handleHomeClick}>Home</button>
<button onClick={handleAddClick}>AddTask</button>
<button onClick={handleRecentClick}>RecentTodo</button>
<button onClick={handleMyClick}>MyTodo</button>
</NavButtonContainer>
</Footer>
</div>
);
};
export default Layout;
Home.js
import React, { forwardRef } from "react";
const Home = forwardRef((props, ref) => {
return (
<div ref={ref} style={{ height: "1000px", backgroundColor: "red" }}>
홈
</div>
);
});
export default Home;오늘의 삽질
어제 예정한 대로, 오늘은 공식문서의 코드를 참고하여 스크롤 기능을 완성하는 것이 목표였다. 개별 컴포넌트에서 forwardRef를 사용하는 것은 큰 문제가 되지 않았다.
분명 제대로 했는데, 맵핑 과정에서 footer가 화면 최하단에 위치하지 않고, 첫 번째 컴포넌트와 두 번째 컴포넌트 사이에 위치했다. Content 태그를 map 외부에서 감싸고 있어서 발생한 일이었다.
왜 처음부터 인지하지 못했는지 매우 화났지만, 목표한 바는 이뤘으니 다행이다. 내일은 RecentTodo까지 기능을 구현하고 스타일링 하는 것을 목표로 하겠다.
More to read
프론트엔드와 백엔드 사이
HTTP 상태 코드는 프론트엔드에서 백엔드로 보냈던 요청의 수행 결과를 의미하는 일종의 약속이며, API를 구성하는 핵심 요소 중 하나입니다. 상태 코드와 관련하여, 백엔드는 잘 모르는 프론트엔드의 슬픈 사정이 있습니다.아래는 요청이 실패했음에도, 백엔드에서 상태 코드
JWT토큰 관리 방식 톺아보기
0. 들어가며 🎯 서비스에 접근하려는 사용자가 누구인지 확인하는 과정을 사용자 인증이라고 합니다. 인증된 사용자에게 주어진 권한을 확인하는 작업은 인가라고 부릅니다. 이번 글에서는 인가는 다루지 않습니다. 사용자 인증에는 많은 방식이 있지만, 오늘은 세션 인증 방
A2AA2A / MCP 멀티 에이전트 오케스트레이션
0. 들어가며 ✍️ Google for Developers에, 레스토랑 공급망 시나리오로 엮은 6대 프로토콜(MCP, A2A, UCP, AP2, A2UI, AG-UI)에 대한 가이드가 게시된 이후, MCP와 A2A부터 구현해 보는 것이 좋을 것 같다는 생각이 들었습니