Next.js Discord

Discord Forum

TS - Cannot read prop

Unanswered
Great Skua posted this in #help-forum
Open in Discord
Great SkuaOP
Hello,
I'm trying to pass props to the child, but when I console log the tags, it provides an empty object
The textData is just an object, but tags is an array of objects.
This is the code
export const DetailsContainer = (
  textData: IServiceTextData,
  tags: IServiceTag[]
) => {
  console.log(tags);

  return (
    <>
      <div>the content...</div>
    </>
  );
};

This is textData, which works with no issues
export interface IServiceTextData {
  title: string;
  subtitle: string;
  originalPrice: number;
  priceColor: string;
  priceBold: boolean;
  priceDiscount: number;
  priceDiscountPercentage: string;
  isPrice: boolean;
}

And this is the tags:
export interface IServiceTag {
  id: number;
  title: string;
  backgroundColor: string;
  isBold: boolean;
}


This is from the parent:
<DetailsContainer {...service.textData} {...service.tags} />

Btw, when I console.log the service.tags in the parent, it shows them all
What is the problem here?

15 Replies

This is the interface of it
export interface IServiceTextData {
  title: string;
  subtitle: string;
  originalPrice: number;
  priceColor: string;
  priceBold: boolean;
  priceDiscount: number;
  priceDiscountPercentage: string;
  isPrice: boolean;
}
Great SkuaOP
Btw, even like that, I still receive empty objects
@joulev
@Great Skua Yes I tried this but I get an error under textData How do I fix that?
oh yeah i wrote it wrong, skill issue
wait a min
export const DetailsContainer = ({
  textData,
  tags
}: {
  textData: IServiceTextData,
  tags: IServiceTag[]
}) => {
  console.log(tags);

  return (
    <>
      <div>the content...</div>
    </>
  );
};
this should be correct
@joulev ts export const DetailsContainer = ({ textData, tags }: { textData: IServiceTextData, tags: IServiceTag[] }) => { console.log(tags); return ( <> <div>the content...</div> </> ); };
Great SkuaOP
The error under textData was fixed, but now I get this
Oh wait
well this is just a type error for you to fix
@Great Skua Oh wait
Great SkuaOP
Ignore this, I still dont understand :X
@Great Skua Ignore this, I still dont understand :X
IServiceTag is an object, you cant pass a string to it
service.tags is an array of string
@joulev `service.tags` is an array of string
Great SkuaOP
Oh I found the issue, thank you! ❤️