Ola Hagen Bendixen
Ola Hagen Bendixen

Reputation: 11

Not able to access value, _value or _rawValue fields of a RefImpl from a sanity query in nuxt typescript

I define my sanity query like this. I inspected the network tab, and the response was correct. The first object printed is a RefImpl. It contains the correct values when I inspect it in the console. However when i try to acccess any of its fields later on, it does not work (last line). It has a correctly populated _value, _rawValue, and a value field. I get null when i try to access them.

const sizePickerQuery = groq`*[_id == "${props.data?._ref}"]`;
const { data: sizePickerData } = await useSanityQuery<SanityDocument[]>(sizePickerQuery);
console.dir(sizePickerData);
console.log(sizePickerData.value);

Any answers on how this could be done better in sanity are also appreciated.

Upvotes: 0

Views: 24

Answers (1)

Ola Hagen Bendixen
Ola Hagen Bendixen

Reputation: 11

Simply had to do it another way in sanity. I requested the whole object instead of the reference. In the question i posted, i was trying to fetch the reference. That worked, but i could not access the value.

Upvotes: 1

Related Questions