Skip to content

Commit 0dd8a93

Browse files
committed
feat: update example for onEdit
1 parent 5257366 commit 0dd8a93

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

examples/basic/pages/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import JsonViewer from '@textea/json-viewer'
22
import type React from 'react'
3+
import { useCallback, useState } from 'react'
4+
5+
import type { InteractionProps } from '../../../src/type'
36

47
const example = {
58
string: 'this is a test string',
@@ -17,9 +20,13 @@ const example = {
1720
}
1821

1922
const IndexPage: React.FC = () => {
23+
const [src, setSrc] = useState<object>(() => example)
24+
const handleEdit = useCallback((update: InteractionProps) => {
25+
setSrc(update.updated_src)
26+
}, [])
2027
return (
2128
<div>
22-
<JsonViewer src={example}/>
29+
<JsonViewer src={src} onEdit={handleEdit}/>
2330
</div>
2431
)
2532
}

0 commit comments

Comments
 (0)