Skip to content

Commit 5e6a9fd

Browse files
committed
refactor to fix perf warns
1 parent 22e9ccf commit 5e6a9fd

File tree

4 files changed

+292
-159
lines changed

4 files changed

+292
-159
lines changed

.oxlintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"no-console": "error",
1212
"no-array-sort": "off",
1313
"rules-of-hooks": "error",
14+
"react/jsx-key": "error",
1415
"react-in-jsx-scope": "off",
1516
// @TODO these rules should be enabled, and the violations fixed
1617
"no-unsafe-type-assertion": "off"
@@ -30,7 +31,8 @@
3031
"rules": {
3132
"jsx-no-new-object-as-prop": "off",
3233
"jsx-no-new-array-as-prop": "off",
33-
"jsx-no-jsx-as-prop": "off"
34+
"jsx-no-jsx-as-prop": "off",
35+
"jsx-no-new-function-as-prop": "off",
3436
}
3537
}
3638
]

demo/components/SpeechSynthesis.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type {PortableTextMarkComponent} from '@portabletext/react'
22

3-
import {useCallback} from 'react'
43

54
interface SpeechSynthesisMark {
65
_type: 'speech'
@@ -15,15 +14,15 @@ export const SpeechSynthesis: PortableTextMarkComponent<SpeechSynthesisMark> = (
1514
value,
1615
}) => {
1716
const pitch = value?.pitch || 1
18-
const handleSynthesis = useCallback(() => {
19-
const msg = new SpeechSynthesisUtterance()
17+
18+
19+
return (
20+
<button type="button" onClick={() => {
21+
const msg = new SpeechSynthesisUtterance()
2022
msg.text = text
2123
msg.pitch = pitch
2224
window.speechSynthesis.speak(msg)
23-
}, [text, pitch])
24-
25-
return (
26-
<button type="button" onClick={handleSynthesis}>
25+
}}>
2726
{children}
2827
</button>
2928
)

demo/components/TermDefinition.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {PortableTextMarkComponent} from '@portabletext/react'
22

33
import {Popover, Text} from '@sanity/ui'
4-
import {useCallback, useState} from 'react'
4+
import {useState} from 'react'
55

66
interface DefinitionMark {
77
_type: 'definition'
@@ -10,8 +10,6 @@ interface DefinitionMark {
1010

1111
export const TermDefinition: PortableTextMarkComponent<DefinitionMark> = ({value, children}) => {
1212
const [isOpen, setOpen] = useState(false)
13-
const handleOpen = useCallback(() => setOpen(true), [setOpen])
14-
const handleClose = useCallback(() => setOpen(false), [setOpen])
1513
return (
1614
<Popover
1715
animate
@@ -25,7 +23,7 @@ export const TermDefinition: PortableTextMarkComponent<DefinitionMark> = ({value
2523
</Text>
2624
}
2725
>
28-
<span style={{textDecoration: 'underline'}} onMouseOver={handleOpen} onMouseOut={handleClose}>
26+
<span style={{textDecoration: 'underline'}} onMouseOver={() => setOpen(true)} onMouseOut={() => setOpen(false)}>
2927
{children}
3028
</span>
3129
</Popover>

0 commit comments

Comments
 (0)