nuxt-modules / nuxt-modules/strapi

Nuxt3: findOne/find() returns undefined when used in a composable

Open
#225 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
TypeScript
Stars
717
Forks
89
Avg merge
7h 3m
Merged PRs (30d)
6

Description

I am trying to make a composable that will get me data dynamically but what I get is undefined. Any ideas on what the issue here is?

composables/useGetTaxonomy.ts

export default async function () {
	const { find, findOne } = useStrapi4();
	const route = useRoute();
	const dataID = route.params.id;

	const dataType = route.name.split('-')[0];
	const data = await findOne(dataType, dataID);
	
	const contentType = 'recipes';
	const contentData = await find(contentType, { [dataType]: dataID });

	return {
		data,
		dataType,
		contentData,
		contentType
	}
}

/pages/[id]-[slug].vue <-- /components/Archive/Taxonomy.vue

<script setup>
const { data, dataType, contentData, contentType } = useGetTaxonomy();
</script>

It returns undefined also when I use useAsyncData.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with composables/useGetTaxonomy.ts and pages/[id]-[slug].vue, then reproduce the page flow through components/Archive/Taxonomy.vue. Inspect the route parameters, useStrapi4 calls, and the behavior when wrapped in useAsyncData. Done means the composable's returned values are defined for the reported route, with the reproduction or a precise cause documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
api, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.