0

I'm wanting to pass savedDocuments through to SavedDocument component. savedDocuments type:

type DocumentUploaderFile = {
    documentId: string;
    id: string;
    name: string;
    size: number;
    status: 'loaded' | 'failed' | 'removing';
}

The error I'm receiving is:

Type '{ document: DocumentUploaderFile; savedDocuments: DocumentUploaderFile[]; }' is not assignable to type 'IntrinsicAttributes & { document: DocumentUploaderFile; }'.
  Property 'savedDocuments' does not exist on type 'IntrinsicAttributes & { document: DocumentUploaderFile; }'.

This is my component I'm trying to pass my prop from:

const AdditionalDocumentationList = ({ savedDocuments }: { savedDocuments: DocumentUploaderFile[] }) => {
  const renderDocuments = (savedDocuments: DocumentUploaderFile[]) => {
    return savedDocuments.map((document: DocumentUploaderFile) => {
      return <SavedDocument document={document} savedDocuments={savedDocuments} />
    })
  }

  return <AdditionalDocumentationWrapper>{renderDocuments(savedDocuments)}</AdditionalDocumentationWrapper>
}

I'm wanting to pass this array through so I can update it when my DeleteIconSmall is clicked in my SavedDocument component, it will remove the matching id from savedDocuments array.

This is the child component I'm trying to pass the prop through to:

const SavedDocument = (
  { document }: { document: DocumentUploaderFile },
  { savedDocuments }: { savedDocuments: DocumentUploaderFile[] }
) => {
  return (
    <SavedDocumentWrapper>
      <StepCompleteIconSmall />
      <SavedDocumentName>{document.name}</SavedDocumentName>
      <DeleteIconSmall />
    </SavedDocumentWrapper>
  )
}
meWho
  • 129
  • 1
  • 8

1 Answers1

1

you are passing the props in the wrong way on the SavedDocument Component should be like this

const SavedDocument = (
  { document, savedDocuments }: { document: DocumentUploaderFile, savedDocuments: DocumentUploaderFile[] }
) => {
  return (
    <SavedDocumentWrapper>
      <StepCompleteIconSmall />
      <SavedDocumentName>{document.name}</SavedDocumentName>
      <DeleteIconSmall />
    </SavedDocumentWrapper>
  )
}
Miguel Caro
  • 280
  • 1
  • 4