Skip to content

Commit 276c6e5

Browse files
authored
[Button,Modal]: fix unique key warning in react (#806)
* fix: key error in button * Create swift-pets-hear.md * fix: modal key warning and close button bug * fix: modal key warning in header
1 parent 66e5e64 commit 276c6e5

File tree

4 files changed

+67
-29
lines changed

4 files changed

+67
-29
lines changed

.changeset/swift-pets-hear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@web3uikit/core": patch
3+
---
4+
5+
[Button]: fix unique key warning in react

apps/example/src/index.tsx

+39-24
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
ConnectButton,
1414
NFT,
1515
SendTransaction,
16+
Modal,
1617
VerifyCode,
18+
Edit,
1719
} from 'web3uikit';
1820

1921
const MockBreadCrumbs = [
@@ -69,30 +71,43 @@ export const App = () => {
6971
<VerifyCode />
7072
</div>
7173
<ConnectButton />
72-
<NFT
73-
address="0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB"
74-
chain="eth"
75-
fetchMetadata
76-
tokenId="1"
77-
/>
78-
<SendTransaction
79-
chainId="0x4"
80-
contractOptions={{
81-
abi: contractData['abi'],
82-
contractAddress:
83-
contractData['contractAddress'],
84-
functionName: 'purchaseCandy',
85-
params: {
86-
_amount: 1,
87-
},
88-
msgValue: 1000000000000000000,
89-
}}
90-
buttonConfig={{
91-
text: 'Send',
92-
theme: 'primary',
93-
}}
94-
notificationConfig={{ dispatch }}
95-
/>
74+
<Modal
75+
isVisible={true}
76+
title={
77+
<div>
78+
<Edit key="icon" />
79+
<Typography>Edit Heading</Typography>{' '}
80+
</div>
81+
}
82+
hasFooter={false}
83+
headerHasBottomBorder={false}
84+
>
85+
<NFT
86+
address="0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB"
87+
chain="eth"
88+
fetchMetadata
89+
tokenId="1"
90+
/>
91+
92+
<SendTransaction
93+
chainId="0x4"
94+
contractOptions={{
95+
abi: contractData['abi'],
96+
contractAddress:
97+
contractData['contractAddress'],
98+
functionName: 'purchaseCandy',
99+
params: {
100+
_amount: 1,
101+
},
102+
msgValue: 1000000000000000000,
103+
}}
104+
buttonConfig={{
105+
text: 'Send',
106+
theme: 'primary',
107+
}}
108+
notificationConfig={{ dispatch }}
109+
/>
110+
</Modal>
96111
<SendTransaction
97112
chainId="0x1"
98113
contractOptions={{

packages/core/src/lib/Button/ButtonBase/ButtonBase.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Loading } from '../../Loading';
22
import styles from './ButtonBase.styles';
33
import { ButtonProps } from '../types';
4+
import React from 'react';
45

56
const { BaseButtonStyled } = styles;
67

@@ -46,8 +47,16 @@ const ButtonBase: React.FC<ButtonProps> = ({
4647
</>
4748
) : (
4849
<>
49-
{text}
50-
{icon && icon}
50+
{text && (
51+
<React.Fragment key={`button-text-${id}`}>
52+
{text}
53+
</React.Fragment>
54+
)}
55+
{icon && (
56+
<React.Fragment key={`button-icon-${id}`}>
57+
{icon}
58+
</React.Fragment>
59+
)}
5160
</>
5261
)}
5362
</span>

packages/core/src/lib/Modal/Modal.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import React, { ReactNode, useEffect, useState } from 'react';
22
import { ModalProps } from './types';
33
import Button from '../Button/Button';
44
import styles from './Modal.styles';
@@ -73,11 +73,20 @@ const Modal: React.FC<ModalProps> = ({
7373
headerHasBottomBorder={headerHasBottomBorder}
7474
>
7575
<>
76-
{typeof title == 'string' ? <h3>{title}</h3> : title}
76+
{typeof title == 'string' ? (
77+
<h3 key="modal-header-title">{title}</h3>
78+
) : (
79+
<React.Fragment key="modal-header-title">
80+
{title}
81+
</React.Fragment>
82+
)}
7783
{closeButton ? (
78-
closeButton
84+
<React.Fragment key="modal-header-close-button">
85+
{closeButton as ReactNode}
86+
</React.Fragment>
7987
) : (
8088
<Button
89+
key="modal-header-close-button"
8190
iconColor="#68738D"
8291
theme="secondary"
8392
radius={100}

0 commit comments

Comments
 (0)