рэд-просмотрщик файлов рендерится только при изменении типа файла - PullRequest
1 голос
/ 17 марта 2020

Я использую средство просмотра файла реакции в веб-части реакции на sharepoint. Работает нормально, пока меняется суффикс файла. Если суффикс остается прежним и изменяется только имя файла, повторная визуализация не выполняется в компоненте response-file-viewer.

Есть что-то особенное для рассмотрения в среде spfx?

import * as React from 'react';
import FileViewer from 'react-file-viewer';
import { LibraryItem } from './LibraryItem';
//import { CustomErrorComponent } from 'custom-error';

export interface IDocumentViewProps {
  fileItem: LibraryItem;
  DocumentViewKey: any;
}

export default class DocumentView extends React.Component<IDocumentViewProps, any> {
  private path: string = "";
  private type: string = "";
  private fileItem: LibraryItem;

  constructor(props: IDocumentViewProps,any) {
    super(props);
    this.state = {
      path: '',
      suffix: ''
    };
  }

  private setFileComponents(item: LibraryItem) {
    if (item) {
      this.path = item.FileRef;
      this.type = item.File_x0020_Type;
      this.setState({ suffix: this.type });
      this.setState({ path: this.path });
    }
  }

  public componentWillReceiveProps(nextProps) {
    const { fileItem } = this.props;
    if (nextProps.fileItem !== fileItem) {
      this.fileItem = nextProps.fileItem;
      this.setFileComponents(this.fileItem);
    }
  }

  public render(): React.ReactElement<IDocumentViewProps,any> {
    return (
      <FileViewer
        fileType={this.state.suffix}
        filePath={this.state.path}
        // errorComponent={CustomErrorComponent}      
        onError={this.onError} 
        on
        />

    );
  }

  private onError(e) {
    // logger.logError(e, 'error in file-viewer');
    console.log(e, 'error in file-viewer');
  }
}

1 Ответ

0 голосов
/ 02 апреля 2020

Решение (обходной путь) - установить ключ = {currentFile.id}. Я получил этот очень полезный совет по github https://github.com/plangrid/react-file-viewer/issues/142 Благодаря https://github.com/yulolimum

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...