강의

멘토링

커뮤니티

Inflearn Community Q&A

alsejr10042690's profile image
alsejr10042690

asked

[Renewal] Creating NodeBird SNS with React

Implementing Redux in practice

useSeletor의 개념 관련 질문드려요

Resolved

Written on

·

324

0

안녕하세요 제로초님 강의를 듣다 헷갈리는 부분이 있어서 질문드립니다.

 

Applayout에서 useSelector를 사용해서 reducers/index에 있는 initialState 중 필요한 값을 가져온 뒤

 

UserPordile, LoginForm에서 dispatch를 하셨는데

 

UserProfile, LoginForm은 어떻게 Applayout에서 가져온 initialState 값에 접근할 수 있는건가요?

 

UserProfile, LoginForm이 Applayout의 return부분에 있어서 가능한건가요?

 

 

expressreactnodejsreduxNext.js

Answer 1

0

zerocho님의 프로필 이미지
zerocho
Instructor

질문이 조금 이해가 안 되는데요. UserProfile이랑 LoginForm은 AppLayout에서 initialState를 가져온 적이 없습니다.

UserProfile이랑 LoginForm은 그냥 useSelector를 통해 리덕스로부터 데이터를 가져오는 겁니다.

hib4888님의 프로필 이미지
hib4888
Questioner

바쁘실텐데 답변 감사합니다. 제가 질문의 의도를 잘 표현하지 못한것같습니다.

 

AppLayout에서 아래 코드를 통해 state를 가져오는 이유가 궁금해서 질문드렸습니다.

const { isLoggedIn } = useSelector(state => state.user);

 

UserProfile이랑 LoginForm에서 dispatch를 통해 action을 수행하셨는데

AppLayout에서 state를 가져오지 않은 상태에서 dispatch만을 통해 중앙저장소에 있는 state의 값을 변경할 수는 없는건가요?

 

만약에 변경할 수 없다면 UserProfile, LoginForm이 아닌 AppLayout에서 state를 가져오는 이유가 궁금합니다

zerocho님의 프로필 이미지
zerocho
Instructor

AppLayout에서 불러온 저 코드는 UserProfile이나 LoginForm이랑 아무 상관이 없습니다.

AppLayout에서 isLoggedIn을 불러오는 이유는 그 아래서 쓰이잖아요. isLoggedIn에 따라서 UserProfile을 보여주냐 LoginForm을 보여주냐를 결정하기 위해서 불러온 것이지

그 안에서 dispatch랑은 일절 관련이 없어요.

hib4888님의 프로필 이미지
hib4888
Questioner

답변 정말 감사합니다 덕분에 이해가 됬습니다 !!

alsejr10042690's profile image
alsejr10042690

asked

Ask a question