質問編集履歴
4
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
React-Table使用
|
1
|
+
React-Tableを使用したJavaScriptをTypeScriptへ変換する件
|
test
CHANGED
File without changes
|
3
問題部分を簡潔にしました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
React-Table使用のJavaScriptをTypeScriptへ変換する
|
test
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
次のサイトを参考に、React-Tableを使用したデータテーブルを作成しています。
|
4
|
-
|
5
|
-
[React Tableの紹介](https://ichi.pro/react-table-no-shokai-121758914446750)
|
3
|
+
[React Tableの紹介](https://ichi.pro/react-table-no-shokai-121758914446750)を参考に、React-Tableを使用したデータテーブルを作成しています。
|
6
|
-
|
4
|
+
|
7
|
-
|
5
|
+
今回の問題は【フィルター付きテーブル】の部分です。
|
8
|
-
|
6
|
+
|
9
|
-
以下
|
7
|
+
以下へ記載するJavaScriptをTypeScriptへ変換したところ、エラーが発生しました。
|
10
|
-
|
8
|
+
|
11
|
-
ご助力よろしくお願いいたします。
|
9
|
+
一部のエラーが解決できませんでしたので、ご助力よろしくお願いいたします。
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
|
11
|
+
|
12
|
+
|
15
|
-
### TypeScript 1
|
13
|
+
### TypeScript 21行目の"[id]"部分
|
16
14
|
|
17
15
|
|
18
16
|
|
@@ -140,147 +138,135 @@
|
|
140
138
|
|
141
139
|
];
|
142
140
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
f
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
first
|
178
|
-
|
179
|
-
l
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
a
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
a
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
l
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
gr
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
age:
|
252
|
-
|
253
|
-
gen
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
{
|
274
|
-
|
275
|
-
firstName: 'William',
|
276
|
-
|
277
|
-
lastName: 'Davis',
|
278
|
-
|
279
|
-
age: 11,
|
280
|
-
|
281
|
-
gender: 'M',
|
282
|
-
|
283
|
-
grade: 6,
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
```TypeScript
|
146
|
+
|
147
|
+
import React, { useMemo } from 'react';
|
148
|
+
|
149
|
+
import { Column } from "react-table";
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
export interface Data {
|
154
|
+
|
155
|
+
firstName: string;
|
156
|
+
|
157
|
+
lastName: string;
|
158
|
+
|
159
|
+
age: number;
|
160
|
+
|
161
|
+
gender: string;
|
162
|
+
|
163
|
+
grade: number;
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
export const columns: Column<Data>[] = [
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
Header: 'Name',
|
174
|
+
|
175
|
+
Footer: info => `Count: ${info.rows.length}`,
|
176
|
+
|
177
|
+
columns: [
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
Header: 'First Name',
|
182
|
+
|
183
|
+
Footer: <hr />,
|
184
|
+
|
185
|
+
accessor: 'firstName',
|
186
|
+
|
187
|
+
filter: (rows, id, filterType) => rows.filter(row => row.values[id].startsWith(filterType)),
|
188
|
+
|
189
|
+
},
|
190
|
+
|
191
|
+
{
|
192
|
+
|
193
|
+
Header: 'Last Name',
|
194
|
+
|
195
|
+
accessor: 'lastName',
|
196
|
+
|
197
|
+
},
|
198
|
+
|
199
|
+
],
|
200
|
+
|
201
|
+
},
|
202
|
+
|
203
|
+
{
|
204
|
+
|
205
|
+
Header: 'Information',
|
206
|
+
|
207
|
+
columns: [
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
Header: 'Age',
|
212
|
+
|
213
|
+
accessor: 'age',
|
214
|
+
|
215
|
+
},
|
216
|
+
|
217
|
+
{
|
218
|
+
|
219
|
+
Header: 'Gender',
|
220
|
+
|
221
|
+
accessor: 'gender',
|
222
|
+
|
223
|
+
},
|
224
|
+
|
225
|
+
{
|
226
|
+
|
227
|
+
Header: info => {
|
228
|
+
|
229
|
+
const message = useMemo(
|
230
|
+
|
231
|
+
() => {
|
232
|
+
|
233
|
+
if (info.rows.length === 0) {
|
234
|
+
|
235
|
+
return 'Unknown';
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
const range = info.rows.reduce((sum, row, i) => {
|
240
|
+
|
241
|
+
if (i === 0) {
|
242
|
+
|
243
|
+
return sum;
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
return {min: Math.min(sum.min, row.values.grade), max: Math.max(sum.max, row.values.grade)}
|
248
|
+
|
249
|
+
}, {min: info.rows[0].values.grade, max: info.rows[0].values.grade});
|
250
|
+
|
251
|
+
return `${range.min} - ${range.max}`;
|
252
|
+
|
253
|
+
},
|
254
|
+
|
255
|
+
[info.rows]
|
256
|
+
|
257
|
+
)
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
return `Grade: (${message})`
|
262
|
+
|
263
|
+
},
|
264
|
+
|
265
|
+
accessor: 'grade',
|
266
|
+
|
267
|
+
},
|
268
|
+
|
269
|
+
],
|
284
270
|
|
285
271
|
},
|
286
272
|
|
@@ -290,323 +276,13 @@
|
|
290
276
|
|
291
277
|
|
292
278
|
|
293
|
-
```TypeScript
|
294
|
-
|
295
|
-
import React, { useMemo } from "react";
|
296
|
-
|
297
|
-
import { Column } from "react-table";
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
export const columns: Column<Data>[] = [
|
302
|
-
|
303
|
-
{
|
304
|
-
|
305
|
-
Header: "Name",
|
306
|
-
|
307
|
-
Footer: info => {
|
308
|
-
|
309
|
-
const count = useMemo(() => info.rows.length, [info.rows]);
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
return `Count: ${count}`;
|
314
|
-
|
315
|
-
},
|
316
|
-
|
317
|
-
columns: [
|
318
|
-
|
319
|
-
{
|
320
|
-
|
321
|
-
Header: "First Name",
|
322
|
-
|
323
|
-
Footer: <hr />,
|
324
|
-
|
325
|
-
accessor: "firstName",
|
326
|
-
|
327
|
-
filter: (rows, columnIds, filterValue) =>
|
328
|
-
|
329
|
-
rows.filter((row) => row.values[columnIds].startsWith(filterValue)),
|
330
|
-
|
331
|
-
},
|
332
|
-
|
333
|
-
{
|
334
|
-
|
335
|
-
Header: "Last Name",
|
336
|
-
|
337
|
-
accessor: "lastName",
|
338
|
-
|
339
|
-
},
|
340
|
-
|
341
|
-
],
|
342
|
-
|
343
|
-
},
|
344
|
-
|
345
|
-
{
|
346
|
-
|
347
|
-
Header: "Information",
|
348
|
-
|
349
|
-
columns: [
|
350
|
-
|
351
|
-
{
|
352
|
-
|
353
|
-
Header: "Age",
|
354
|
-
|
355
|
-
accessor: "age",
|
356
|
-
|
357
|
-
},
|
358
|
-
|
359
|
-
{
|
360
|
-
|
361
|
-
Header: "Gender",
|
362
|
-
|
363
|
-
accessor: "gender",
|
364
|
-
|
365
|
-
},
|
366
|
-
|
367
|
-
{
|
368
|
-
|
369
|
-
Header: info => {
|
370
|
-
|
371
|
-
const message = useMemo(() => {
|
372
|
-
|
373
|
-
if (info.rows.length === 0) {
|
374
|
-
|
375
|
-
return "Unknown";
|
376
|
-
|
377
|
-
}
|
378
|
-
|
379
|
-
const range = info.rows.reduce(
|
380
|
-
|
381
|
-
(sum, row, i) => {
|
382
|
-
|
383
|
-
if (i === 0) {
|
384
|
-
|
385
|
-
return sum;
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
return {
|
390
|
-
|
391
|
-
min: Math.min(sum.min, row.values.grade),
|
392
|
-
|
393
|
-
max: Math.max(sum.max, row.values.grade),
|
394
|
-
|
395
|
-
};
|
396
|
-
|
397
|
-
},
|
398
|
-
|
399
|
-
{ min: info.rows[0].values.grade, max: info.rows[0].values.grade }
|
400
|
-
|
401
|
-
);
|
402
|
-
|
403
|
-
return `${range.min} - ${range.max}`;
|
404
|
-
|
405
|
-
}, [info.rows]);
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
return `Grade: (${message})`;
|
410
|
-
|
411
|
-
},
|
412
|
-
|
413
|
-
accessor: "grade",
|
414
|
-
|
415
|
-
},
|
416
|
-
|
417
|
-
],
|
418
|
-
|
419
|
-
},
|
420
|
-
|
421
|
-
];
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
export interface Data {
|
426
|
-
|
427
|
-
firstName: string;
|
428
|
-
|
429
|
-
lastName: string;
|
430
|
-
|
431
|
-
age: number;
|
432
|
-
|
433
|
-
gender: string;
|
434
|
-
|
435
|
-
grade: number;
|
436
|
-
|
437
|
-
}
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
export const data: Data[] = [
|
442
|
-
|
443
|
-
{
|
444
|
-
|
445
|
-
firstName: "Alice",
|
446
|
-
|
447
|
-
lastName: "Johnson",
|
448
|
-
|
449
|
-
age: 9,
|
450
|
-
|
451
|
-
gender: "F",
|
452
|
-
|
453
|
-
grade: 4,
|
454
|
-
|
455
|
-
},
|
456
|
-
|
457
|
-
{
|
458
|
-
|
459
|
-
firstName: "Mike",
|
460
|
-
|
461
|
-
lastName: "Ford",
|
462
|
-
|
463
|
-
age: 5,
|
464
|
-
|
465
|
-
gender: "M",
|
466
|
-
|
467
|
-
grade: 1,
|
468
|
-
|
469
|
-
},
|
470
|
-
|
471
|
-
{
|
472
|
-
|
473
|
-
firstName: "John",
|
474
|
-
|
475
|
-
lastName: "Smith",
|
476
|
-
|
477
|
-
age: 8,
|
478
|
-
|
479
|
-
gender: "M",
|
480
|
-
|
481
|
-
grade: 4,
|
482
|
-
|
483
|
-
},
|
484
|
-
|
485
|
-
{
|
486
|
-
|
487
|
-
firstName: "Joe",
|
488
|
-
|
489
|
-
lastName: "Johnson",
|
490
|
-
|
491
|
-
age: 11,
|
492
|
-
|
493
|
-
gender: "M",
|
494
|
-
|
495
|
-
grade: 6,
|
496
|
-
|
497
|
-
},
|
498
|
-
|
499
|
-
{
|
500
|
-
|
501
|
-
firstName: "Linda",
|
502
|
-
|
503
|
-
lastName: "Ford",
|
504
|
-
|
505
|
-
age: 8,
|
506
|
-
|
507
|
-
gender: "F",
|
508
|
-
|
509
|
-
grade: 5,
|
510
|
-
|
511
|
-
},
|
512
|
-
|
513
|
-
{
|
514
|
-
|
515
|
-
firstName: "Noah",
|
516
|
-
|
517
|
-
lastName: "Wilson",
|
518
|
-
|
519
|
-
age: 9,
|
520
|
-
|
521
|
-
gender: "M",
|
522
|
-
|
523
|
-
grade: 3,
|
524
|
-
|
525
|
-
},
|
526
|
-
|
527
|
-
{
|
528
|
-
|
529
|
-
firstName: "Emma",
|
530
|
-
|
531
|
-
lastName: "Lee",
|
532
|
-
|
533
|
-
age: 7,
|
534
|
-
|
535
|
-
gender: "F",
|
536
|
-
|
537
|
-
grade: 3,
|
538
|
-
|
539
|
-
},
|
540
|
-
|
541
|
-
{
|
542
|
-
|
543
|
-
firstName: "James",
|
544
|
-
|
545
|
-
lastName: "Jones",
|
546
|
-
|
547
|
-
age: 10,
|
548
|
-
|
549
|
-
gender: "M",
|
550
|
-
|
551
|
-
grade: 5,
|
552
|
-
|
553
|
-
},
|
554
|
-
|
555
|
-
{
|
556
|
-
|
557
|
-
firstName: "Mia",
|
558
|
-
|
559
|
-
lastName: "Brown",
|
560
|
-
|
561
|
-
age: 8,
|
562
|
-
|
563
|
-
gender: "F",
|
564
|
-
|
565
|
-
grade: 5,
|
566
|
-
|
567
|
-
},
|
568
|
-
|
569
|
-
{
|
570
|
-
|
571
|
-
firstName: "William",
|
572
|
-
|
573
|
-
lastName: "Davis",
|
574
|
-
|
575
|
-
age: 11,
|
576
|
-
|
577
|
-
gender: "M",
|
578
|
-
|
579
|
-
grade: 6,
|
580
|
-
|
581
|
-
},
|
582
|
-
|
583
|
-
{
|
584
|
-
|
585
|
-
firstName: "Abc",
|
586
|
-
|
587
|
-
lastName: "Xyz",
|
588
|
-
|
589
|
-
age: 20,
|
590
|
-
|
591
|
-
gender: "F",
|
592
|
-
|
593
|
-
grade: 6,
|
594
|
-
|
595
|
-
},
|
596
|
-
|
597
|
-
];
|
598
|
-
|
599
|
-
```
|
600
|
-
|
601
|
-
|
602
|
-
|
603
279
|
### 試したこと
|
604
280
|
|
605
281
|
|
606
282
|
|
607
|
-
any型やtoString()
|
283
|
+
any型やtoString()でエラー回避はできます。
|
608
|
-
|
284
|
+
|
609
|
-
しかし、根本的な解決
|
285
|
+
しかし、根本的な解決ではありませんでした。
|
610
286
|
|
611
287
|
|
612
288
|
|
2
軽微な編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,10 +12,6 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
■■な機能を実装中に以下のエラーメッセージが発生しました。
|
16
|
-
|
17
|
-
|
18
|
-
|
19
15
|
### TypeScript 18行目の[columnIds]部分
|
20
16
|
|
21
17
|
|
1
ソース内容変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -332,8 +332,6 @@
|
|
332
332
|
|
333
333
|
rows.filter((row) => row.values[columnIds].startsWith(filterValue)),
|
334
334
|
|
335
|
-
row.values[columnIds.toString()].startsWith(filterValue)),
|
336
|
-
|
337
335
|
},
|
338
336
|
|
339
337
|
{
|