Skip to content

Commit

Permalink
6.4.1 FriendMain 컴포넌트 개선하기
Browse files Browse the repository at this point in the history
  • Loading branch information
b-chae committed Oct 22, 2021
1 parent 5199f40 commit 807054a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/friend/container/FriendMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import { addFriend } from "../state";
export default function FriendMain() {
const [, forceUpdate] = useReducer(v => v+1, 0)
useEffect(() => {
const unsubscribe = store.subscribe(() => forceUpdate())
let prevFriends = store.getState().friend.friends
const unsubscribe = store.subscribe(() => {
// 책에서와 다르게 코딩한 부분
// prevFriends !== store.friends
if (prevFriends !== store.getState().friend.friends){
forceUpdate()
}
prevFriends = store.getState().friend.friends
})
return () => unsubscribe()
}, [])

Expand Down

0 comments on commit 807054a

Please sign in to comment.