Skip to content

Commit

Permalink
fix: fix reactivity bug in useProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
levchak0910 committed Nov 1, 2020
1 parent 7fe7872 commit e3a0441
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/composable/useProfile.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { reactive, watchEffect } from 'vue'
import { ComputedRef, reactive, watch } from 'vue'

import { getProfile } from '../services/profile/getProfile'

export function useProfile (username: string) {
interface UseProfileProps {
username: ComputedRef<string>
}

export function useProfile ({ username }: UseProfileProps) {
const profile = reactive<Profile>({} as Profile)

async function fetchProfile () {
const profileData = await getProfile(username)
const profileData = await getProfile(username.value)
updateProfile(profileData)
}

async function updateProfile (profileData: Profile) {
Object.assign(profile, profileData)
}

watchEffect(() => {
fetchProfile()
})
watch(username, fetchProfile, { immediate: true })

return {
profile,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default defineComponent({
const { user, isAuthorized } = store.user
const { profile, updateProfile } = useProfile(username.value)
const { profile, updateProfile } = useProfile({ username })
const { followProcessGoing, toggleFollow } = useFollow({
following: computed<boolean>(() => profile.following),
Expand Down

0 comments on commit e3a0441

Please sign in to comment.