ReactJS:获取响应不会返回componentDidMount;无法加载PDF

时间:2019-05-04 23:10:30

标签: reactjs react-pdf

在ReactJS中,组件在收到Fetch响应后不会重新渲染。因此,总是在屏幕上看到“正在加载PDF ...”消息

componentDidMount代码如下,

fread()

获取后,不会打印getData值(数据)。由于未重新渲染此组件,因此未设置pdfData。同时,数组值会打印在getData()中。

使用react-pdf库将返回的数据呈现为pdf

data.table

getData在下面给出,

A <- data.table::fread("
Position    phaseGroup  phaseGroup_2    phaseGroup_3    Synonymous  Information Phasing Pha_Syn Grouped yPos
5.85E+04    1   1   1   16  1.1 Phased  Phased-16   1   1
5.96E+04    1   1   1   16  1.1 Phased  Phased-16   1   2
6.22E+04    1   1   1   16  1.1 Phased  Phased-16   1   3
6.26E+04    1   1   1   16  1.1 Phased  Phased-16   1   4
7.22E+04    NA  1   1   16  1.NA    Unphased    Unphased-16 1   5
7.30E+04    1   1   1   16  1.1 Phased  Phased-16   1   6
2.03E+05    2   2   2.1 16  1.2 Phased  Phased-16   1   7
2.48E+05    2   2   2.1 1   1.2 Phased  Phased-1    1   8
2.53E+05    2   2   2.1 16  1.2 Phased  Phased-16   1   9
2.53E+05    2   2   2.1 16  1.2 Phased  Phased-16   1   10
2.54E+05    2   2   2.1 16  1.2 Phased  Phased-16   1   11
2.54E+05    2   2   2.1 16  1.2 Phased  Phased-16   1   12
2.54E+05    NA  2   2.2 16  1.NA    Unphased    Unphased-16 1   13
2.55E+05    2   2   2.2 16  1.2 Phased  Phased-16   1   14
2.56E+05    2   2   2.2 16  1.2 Phased  Phased-16   1   15
2.58E+05    2   2   2.2 16  1.2 Phased  Phased-16   1   16
2.61E+05    2   2   2.2 16  1.2 Phased  Phased-16   1   17
5.76E+05    3   3   3.1 16  1.3 Phased  Phased-16   1   18
5.77E+05    3   3   3.1 16  1.3 Phased  Phased-16   1   19
5.77E+05    3   3   3.1 16  1.3 Phased  Phased-16   1   20
5.79E+05    3   3   3.1 16  1.3 Phased  Phased-16   1   21
6.22E+05    3   3   3.1 16  1.3 Phased  Phased-16   1   22
6.23E+05    3   3   3.1 1   1.3 Phased  Phased-1    1   23
6.24E+05    3   3   3.2 16  1.3 Phased  Phased-16   1   24
6.25E+05    3   3   3.2 16  1.3 Phased  Phased-16   1   25
6.26E+05    3   3   3.2 16  1.3 Phased  Phased-16   1   26
6.27E+05    3   3   3.2 16  1.3 Phased  Phased-16   1   27
6.29E+05    3   3   3.2 16  1.3 Phased  Phased-16   1   28
6.29E+05    3   3   3.2 16  1.3 Phased  Phased-16   1   29
6.31E+05    3   3   3.3 16  1.3 Phased  Phased-16   1   30
6.32E+05    3   3   3.3 16  1.3 Phased  Phased-16   1   31
6.32E+05    3   3   3.3 16  1.3 Phased  Phased-16   1   32
6.34E+05    3   3   3.3 16  1.3 Phased  Phased-16   1   33
6.35E+05    3   3   3.3 16  1.3 Phased  Phased-16   1   34
6.37E+05    3   3   3.3 16  1.3 Phased  Phased-16   1   35
6.76E+05    3   3   3.4 16  1.3 Phased  Phased-16   1   36
6.82E+05    3   3   3.4 16  1.3 Phased  Phased-16   1   37
7.40E+05    3   3   3.4 16  1.3 Phased  Phased-16   1   38
7.57E+05    3   3   3.4 16  1.3 Phased  Phased-16   1   39
7.60E+05    3   3   3.4 16  1.3 Phased  Phased-16   1   40
7.61E+05    3   3   3.4 16  1.3 Phased  Phased-16   1   41
7.61E+05    3.5 3.5 3.5 16  2.1 Phased  Phased-16   2   41.5
2.03E+06    4   4   4   16  3.4 Phased  Phased-16   3   42
2.10E+06    4   4   4   1   3.4 Phased  Phased-1    3   43
2.15E+06    4   4   4   16  3.4 Phased  Phased-16   3   44
2.16E+06    4   4   4   16  3.4 Phased  Phased-16   3   45
2.16E+06    4   4   4   16  3.4 Phased  Phased-16   3   46
2.16E+06    4   4   4   16  3.4 Phased  Phased-16   3   47
2.17E+06    4   4   4   1   3.4 Phased  Phased-1    3   48
2.18E+06    NA  4   4   1   3.NA    Unphased    Unphased-1  3   49
2.36E+06    5   5   5   16  3.5 Phased  Phased-16   3   50
2.36E+06    5   5   5   16  3.5 Phased  Phased-16   3   51
2.37E+06    5   5   5   16  3.5 Phased  Phased-16   3   52
2.37E+06    5   5   5   1   3.5 Phased  Phased-1    3   53
2.37E+06    5   5   5   1   3.5 Phased  Phased-1    3   54
2.37E+06    5   5   5   16  3.5 Phased  Phased-16   3   55
2.37E+06    5   5   5   16  3.5 Phased  Phased-16   3   56
2.37E+06    5   5   5   1   3.5 Phased  Phased-1    3   57
2.50E+06    5   5   5   16  3.5 Phased  Phased-16   3   58
2.50E+06    5   5   5   16  3.5 Phased  Phased-16   3   59
2.53E+06    5   5   5   1   3.5 Phased  Phased-1    3   60
2.54E+06    5   5   5   16  3.5 Phased  Phased-16   3   61
2.54E+06    5   5   5   1   3.5 Phased  Phased-1    3   62
2.56E+06    5   5   5   16  3.5 Phased  Phased-16   3   63
2.60E+06    5   5   5   16  3.5 Phased  Phased-16   3   64
2.62E+06    5   5   5   16  3.5 Phased  Phased-16   3   65
3.04E+06    NA  5   5   1   4.NA    Unphased    Unphased-1  4   66
3.17E+06    NA  5   5   1   4.NA    Unphased    Unphased-1  4   67
3.84E+06    NA  5   5   16  4.NA    Unphased    Unphased-16 4   68
4.00E+06    6   6   6   16  5.6 Phased  Phased-16   5   69
4.00E+06    6   6   6   16  5.6 Phased  Phased-16   5   70
4.00E+06    6   6   6   16  5.6 Phased  Phased-16   5   71
4.00E+06    6   6   6   1   5.6 Phased  Phased-1    5   72
4.00E+06    6   6   6   16  5.6 Phased  Phased-16   5   73
4.00E+06    NA  6   6   16  5.NA    Unphased    Unphased-16 5   74
4.00E+06    NA  6   6   16  5.NA    Unphased    Unphased-16 5   75
4.00E+06    7   7   7   16  5.7 Phased  Phased-16   5   76
4.00E+06    7   7   7   16  5.7 Phased  Phased-16   5   77
4.00E+06    7   7   7   1   5.7 Phased  Phased-1    5   78
4.00E+06    7   7   7   1   5.7 Phased  Phased-1    5   79
4.00E+06    7   7   7   16  5.7 Phased  Phased-16   5   80
4.00E+06    7   7   7   16  5.7 Phased  Phased-16   5   81
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   82
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   83
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   84
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   85
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   86
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   87
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   88
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   89
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   90
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   91
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   92
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   93
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   94
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   95
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   96
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   97
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   98
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   99
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   100
4.00E+06    8   8   8   16  5.8 Phased  Phased-16   5   101
4.01E+06    8   8   8   16  5.8 Phased  Phased-16   5   102
4.01E+06    8   8   8   16  5.8 Phased  Phased-16   5   103
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   104
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   105
4.01E+06    NA  9   9   16  5.NA    Unphased    Unphased-16 5   106
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   107
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   108
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   109
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   110
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   111
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   112
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   113
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   114
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   115
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   116
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   117
4.01E+06    9   9   9   16  5.9 Phased  Phased-16   5   118
4.01E+06    NA  9   9   1   5.NA    Unphased    Unphased-1  5   119
4.02E+06    9   9   9   16  5.9 Phased  Phased-16   5   120
4.02E+06    10  10  10  1   5.1 Phased  Phased-1    5   121
4.02E+06    10  10  10  16  5.1 Phased  Phased-16   5   122
4.02E+06    NA  10  10  1   5.NA    Unphased    Unphased-1  5   123
4.02E+06    10  10  10  16  5.1 Phased  Phased-16   5   124
4.02E+06    10  10  10  16  5.1 Phased  Phased-16   5   125
4.02E+06    10  10  10  1   5.1 Phased  Phased-1    5   126
4.02E+06    10  10  10  1   5.1 Phased  Phased-1    5   127
4.02E+06    10  10  10  1   5.1 Phased  Phased-1    5   128
4.02E+06    NA  10  10  1   5.NA    Unphased    Unphased-1  5   129
4.02E+06    10  10  10  1   5.1 Phased  Phased-1    5   130
4.02E+06    10  10  10  1   5.1 Phased  Phased-1    5   131
4.02E+06    10  10  10  16  5.1 Phased  Phased-16   5   132
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   133
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   134
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   135
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   136
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   137
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   138
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   139
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   140
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   141
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   142
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   143
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   144
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   145
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   146
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   147
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   148
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   149
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   150
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   151
4.03E+06    NA  10  10  16  5.NA    Phased  Phased-16   5   152
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   153
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   154
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   155
4.03E+06    10  10  10  16  5.1 Phased  Phased-16   5   156
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   157
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   158
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   159
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   160
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   161
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   162
4.04E+06    NA  10  10  16  5.NA    Unphased    Unphased-16 5   163
4.04E+06    NA  10  10  16  5.NA    Unphased    Unphased-16 5   164
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   165
4.04E+06    NA  10  10  16  5.NA    Unphased    Unphased-16 5   166
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   167
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   168
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   169
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   170
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   171
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   172
4.04E+06    NA  10  10  16  5.NA    Unphased    Unphased-16 5   173
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   174
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   175
4.04E+06    NA  10  10  16  5.NA    Unphased    Unphased-16 5   176
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   177
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   178
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   179
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   180
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   181
4.04E+06    10  10  10  1   5.1 Phased  Phased-1    5   182
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   183
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   184
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   185
4.04E+06    NA  10  10  16  5.NA    Unphased    Unphased-16 5   186
4.04E+06    10  10  10  16  5.1 Phased  Phased-16   5   187
4.05E+06    10  10  10  16  5.1 Phased  Phased-16   5   188
4.05E+06    10  10  10  16  5.1 Phased  Phased-16   5   189
4.05E+06    10  10  10  16  5.1 Phased  Phased-16   5   190
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   191
4.05E+06    10  10  10  16  5.1 Phased  Phased-16   5   192
4.05E+06    10  10  10  16  5.1 Phased  Phased-16   5   193
4.05E+06    10  10  10  16  5.1 Phased  Phased-16   5   194
4.05E+06    10  10  10  16  5.1 Phased  Phased-16   5   195
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   196
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   197
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   198
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   199
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   200
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   201
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   202
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   203
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   204
4.05E+06    10  10  10  16  5.1 Phased  Phased-16   5   205
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   206
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   207
4.05E+06    10  10  10  1   5.1 Phased  Phased-1    5   208
4.59E+06    NA  10  10  16  5.NA    Unphased    Unphased-16 5   209")

1 个答案:

答案 0 :(得分:2)

由于您的getData函数为async,因此您需要在await中将componentDidMount的结果或根据诺言行事(假设您已经{{1} } ing您的API调用)。例如:

正在等待:

await

或承诺:

async componentDidMount() {
    const { getData } = this.props;
    let data =  await getData(); // <-- Await the async here
    this.setState({ pdfData: data });
}