Skip to content

Commit

Permalink
Add userUpdated hook (#37)
Browse files Browse the repository at this point in the history
* add userUpdated hook

* Update hooks.md

* Update hooks.md
  • Loading branch information
stafyniaksacha authored Aug 25, 2020
1 parent f4b6985 commit 83eb2e6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
41 changes: 40 additions & 1 deletion docs/content/en/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,43 @@ export default ({ $strapi, app }) => {
app.$toast.error(e.message)
})
}
```
```

### `userUpdated`

You can register an `userUpdated` hook to force refetch inside components:


```vue{}[components/navbar.vue]
<template>
<div>
<p v-for="(userInvoice, index) in userInvoices" key="index">
{{ index }}
</p>
</div>
</template>
<script>
export default {
data() {
return {
unregisterUserHook: null,
userInvoices: []
}
},
async fetch() {
// get user related data
},
mounted() {
this.unregisterUserHook = this.$strapi.hook('userUpdated', (user) => {
this.$fetch()
})
},
beforeDestroy() {
if (this.unregisterUserHook) {
this.unregisterUserHook()
}
},
}
</script>
```
1 change: 1 addition & 0 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Strapi extends Hookable {

setUser (user) {
this.user = user
this.callHook('userUpdated', user)
}

find (entity, searchParams) {
Expand Down

0 comments on commit 83eb2e6

Please sign in to comment.