-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63db93c
commit b8eb916
Showing
4 changed files
with
456 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/frontend/admin/src/components/atoms/VanillaJSONEditor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useRef, useEffect } from "react"; | ||
import { JSONEditor } from "vanilla-jsoneditor"; | ||
|
||
export default function SvelteJSONEditor(props) { | ||
const refContainer = useRef(null); | ||
const refEditor = useRef(null); | ||
|
||
useEffect(() => { | ||
// create editor | ||
console.log("create editor", refContainer.current); | ||
refEditor.current = new JSONEditor({ | ||
target: refContainer.current, | ||
props: {} | ||
}); | ||
|
||
return () => { | ||
// destroy editor | ||
if (refEditor.current) { | ||
console.log("destroy editor"); | ||
refEditor.current.destroy(); | ||
refEditor.current = null; | ||
} | ||
}; | ||
}, []); | ||
|
||
// update props | ||
useEffect(() => { | ||
if (refEditor.current) { | ||
console.log("update props", props); | ||
refEditor.current.updateProps(props); | ||
} | ||
}, [props]); | ||
|
||
return <div className="vanilla-jsoneditor-react" ref={refContainer}></div>; | ||
} |
Oops, something went wrong.