Skip to content

Commit 0e1293a

Browse files
committed
chore: Patch out those annoying React key warnings
1 parent a1e8485 commit 0e1293a

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/globals/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '@/globals/patches';
2+
import '@/globals/prototypes';

src/globals/patches.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable no-console */
2+
3+
/**
4+
* Patch out React key warnings
5+
* @see https://github.com/facebook/react/issues/12567
6+
*/
7+
const baseConsoleError = console.error.bind(console);
8+
const keyWarningPattern = 'Warning: Each child in a list should have a unique "key" prop.';
9+
10+
console.error = function (...args) {
11+
if (typeof args[0] === 'string' && args[0].startsWith(keyWarningPattern)) {
12+
return;
13+
}
14+
return baseConsoleError(...args);
15+
};

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dotenv/config';
2-
import '@/globals/prototypes';
2+
import '@/globals';
33

44
import { log } from '@/utils/logger';
55

0 commit comments

Comments
 (0)