-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] 스크롤 따라 헤더바 상태 변경되는 것 구현 #69
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리팩토링만 해 주시면 감사하겠습니다.
src/header/index.jsx
Outdated
return { | ||
"--pos": position, | ||
}; | ||
if (currentSection > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왜 eager return을 빼고 도로 if문으로 돌아오셨나요?
src/header/index.jsx
Outdated
const isVisibleList = useSectionStore((state) => state.isVisibleList); | ||
const [currentSection, setCurrentSection] = useState(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zustand의 훅 안의 있는 함수는 상태에서 비롯된 다른 상태(derived state)를 계산할 수 있습니다.
그래서, 이런 게 가능합니다.
const currentSection = useSectionStore( (state)=>{
return state.isVisibleList.findIndex((value) => value);
} );
src/header/index.jsx
Outdated
useEffect(() => { | ||
const idx = isVisibleList.findIndex((value) => value === true); | ||
setCurrentSection(idx); | ||
}, [isVisibleList]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상태가 바뀌었을 때 useEffect로 다른 상태를 동기적으로 계산하는 것은 별로 좋은 패턴이 아닙니다. (렌더링이 2번 일어남)
const currentSection = useSectionStore((state) => { | ||
return state.isVisibleList.findIndex((value) => value === true); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good
#️⃣ 연관 이슈
📝 작업 내용