Skip to content

Instantly share code, notes, and snippets.

@damianof
Forked from 3aluw/Deskree
Last active January 12, 2023 20:15
Show Gist options
  • Select an option

  • Save damianof/63a18280a89df7de6c4491353a31f3bd to your computer and use it in GitHub Desktop.

Select an option

Save damianof/63a18280a89df7de6c4491353a31f3bd to your computer and use it in GitHub Desktop.
import { reactive, ref, onMounted } from 'vue'
export const useDeskree = (props) => {
const userInfo = ref({})
//the user object that has some user functions such as login ...
const user = {
get() {
return loggedInUser
},
//other functions
}
//this function run on the mounted hook it fetches the user data.
async function initUser(userId) {
if (typeof props.userId === "string") {
try {
const res = await dbRestRequest(`/users/${userIdOrUser}`)
userInfo.value = {
...res.data
}
} catch {}
//ctach an other staff
}
}
onMounted(async () => {
await initUser()
})
return {
user: userInfo
}
}
//I want to make the get function awaits for initUser so it doesn't return a null
<script setup>
const { user } = useDeskree();
console.log(user.value) // should now log
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment