Skip to content

Commit a6c6ca0

Browse files
committed
mount fix
1 parent 306f125 commit a6c6ca0

1 file changed

Lines changed: 17 additions & 26 deletions

File tree

src/components/pages/profile/[name]/ProfileEmptyBanner.tsx

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useEffect, useRef } from 'react'
21
import { useTranslation } from 'react-i18next'
32
import styled, { css } from 'styled-components'
43

@@ -193,30 +192,6 @@ export function ProfileEmptyBanner({ name }: { name: string }) {
193192
(i) => i.label === t('tabs.profile.actions.editProfile.label'),
194193
)
195194

196-
const btnRef = useRef<HTMLButtonElement>(null)
197-
198-
useEffect(() => {
199-
if (btnRef.current) {
200-
const btn = btnRef.current
201-
btn.style.setProperty('--x', '0px')
202-
btn.style.setProperty('--y', '0px')
203-
const handleMouseMove = (e: MouseEvent) => {
204-
const box = btn.getBoundingClientRect()
205-
if (!box) return
206-
const x = e.clientX - box.left
207-
const y = e.clientY - box.top
208-
209-
btn.style.setProperty('--x', `${x}px`)
210-
btn.style.setProperty('--y', `${y}px`)
211-
}
212-
btn.addEventListener('mousemove', handleMouseMove)
213-
214-
return () => {
215-
btn.removeEventListener('mousemove', handleMouseMove)
216-
}
217-
}
218-
}, [])
219-
220195
if (records.length || isProfileLoading || !action || !canEditRecords) return null
221196

222197
return (
@@ -234,9 +209,25 @@ export function ProfileEmptyBanner({ name }: { name: string }) {
234209
</div>
235210
<GradientButton
236211
width="auto"
237-
ref={btnRef}
238212
colorStyle="transparent"
239213
onClick={() => action?.onClick()}
214+
style={
215+
{
216+
// eslint-disable-next-line @typescript-eslint/naming-convention
217+
'--x': '0px',
218+
// eslint-disable-next-line @typescript-eslint/naming-convention
219+
'--y': '0px',
220+
} as React.CSSProperties
221+
}
222+
onMouseMove={(e) => {
223+
const box = e.currentTarget.getBoundingClientRect()
224+
if (!box) return
225+
const x = e.clientX - box.left
226+
const y = e.clientY - box.top
227+
228+
e.currentTarget.style.setProperty('--x', `${x}px`)
229+
e.currentTarget.style.setProperty('--y', `${y}px`)
230+
}}
240231
>
241232
{t('banner.empty.action')}
242233
</GradientButton>

0 commit comments

Comments
 (0)