React
[TIL/React] 2023/06/19
App.js아주 좋은 학습용 코드를 구했다. 이번 주는 이 코드를 이해하고 투두리스트를 적용하는 것을 목표로 하겠다.
2023년 6월 19일2min read
App.js
code
import React, { useRef, useState, useEffect } from "react";
import styled from "styled-components";
const DETAIL_NAV = [
{ idx: 0, name: "Section 1" },
{ idx: 1, name: "Section 2" },
{ idx: 2, name: "Section 3" },
{ idx: 3, name: "Section 4" },
// Add more sections as needed
];
const App = () => {
const scrollRef = useRef([]);
const navRef = useRef([]);
const [activeSection, setActiveSection] = useState(null);
const handleNavClick = (index) => {
setActiveSection(index);
};
useEffect(() => {
scrollRef.current[activeSection]?.scrollIntoView({ behavior: "smooth" });
setActiveSection(null);
}, [activeSection]);
useEffect(() => {
const changeNavBtnStyle = () => {
scrollRef.current.forEach((ref, idx) => {
if (ref.offsetTop - 180 < window.scrollY) {
navRef.current.forEach((ref) => {
ref.classList.remove("active");
});
navRef.current[idx].classList.add("active");
}
});
};
window.addEventListener("scroll", changeNavBtnStyle);
return () => {
window.removeEventListener("scroll", changeNavBtnStyle);
};
}, []);
return (
<div>
<Nav>
{DETAIL_NAV.map(({ idx, name }) => (
<NavBtn
key={idx}
ref={(ref) => (navRef.current[idx] = ref)}
onClick={() => handleNavClick(idx)}
className={activeSection === idx ? "active" : ""}
>
{name}
</NavBtn>
))}
</Nav>
<Section ref={(ref) => (scrollRef.current[0] = ref)}>
<h2>Section 1</h2>
<p>Content for section 1...</p>
</Section>
<Section ref={(ref) => (scrollRef.current[1] = ref)}>
<h2>Section 2</h2>
<p>Content for section 2...</p>
</Section>
<Section ref={(ref) => (scrollRef.current[2] = ref)}>
<h2>Section 3</h2>
<p>Content for section 3...</p>
</Section>
<Section ref={(ref) => (scrollRef.current[3] = ref)}>
<h2>Section 4</h2>
<p>Content for section 4...</p>
</Section>
{/* Add more sections as needed */}
</div>
);
};
const Nav = styled.nav`
position: sticky;
top: 0;
left: 0;
width: 100%;
background-color: #f0f0f0;
padding: 10px;
display: flex;
justify-content: center;
z-index: 999;
`;
const NavBtn = styled.button`
border: none;
background-color: transparent;
padding: 5px 10px;
margin: 0 5px;
font-weight: bold;
color: #555;
cursor: pointer;
outline: none;
&.active {
color: blue;
}
`;
const Section = styled.section`
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #fafafa;
scroll-margin-top: 100px;
h2 {
font-size: 24px;
margin-bottom: 10px;
}
`;
export default App;
아주 좋은 학습용 코드를 구했다. 이번 주는 이 코드를 이해하고 투두리스트를 적용하는 것을 목표로 하겠다.
More to read
AI
AI&ML 기초
Reference: https://bettermesol.github.io/ml/2019/09/16/ai-ml-dl/AI: 기계가 사람처럼 생각하고 판단하게 만드는 가장 넓은 범주의 기술입니다.ML: 데이터를 학습하여 스스로 규칙을 찾아내는 AI의 한 분야로,
'AI Agent Economy'Novitas : AI Agent가 지갑을 가지는 세상
얼마 전, 미래에셋증권 리서치 리포트(올해는 이더리움이다: 에이전트 시대의 Near Automata)를 접하게 되었습니다. AI Agent를 인간과 함께할 경제 주체로 바라보는 시각에 적잖이 충격을 받았더랬죠.한 가지 짚고 넘어갈 부분이 있습니다. 우리가 흔히 'AI'
'ERC-8004'Novitas: AI 에이전트 경제 주체
Web 4.0을 한 문장으로 정의하면 Sovereign Transact입니다.AI가 인간의 허락 없이 지갑을 소유하고, 결제를 수행하며, 인프라를 통제하는 주권적 경제 주체가 되는 세계입니다. Web 3.0이 블록체인 기반의 탈중앙화를 실현했다면, Web 4.0은 그