Last active
December 3, 2022 05:52
-
-
Save JenniferFuBook/0f7eb870a49fd3cf2291fa6737120633 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { useEffect, useState } from 'react'; | |
import Editor from '@monaco-editor/react'; | |
const FileUploader = ({ onFileLoad }) => { | |
return <input type="file" onChange={(e) => onFileLoad(e.target.files[0])} />; | |
}; | |
function App() { | |
const [file, setFile] = useState(); | |
const [value, setValue] = useState(); | |
useEffect(() => { | |
if (file) { | |
var reader = new FileReader(); | |
reader.onload = async (e) => { | |
setValue(e.target.result); | |
}; | |
reader.readAsText(file); | |
} | |
}, [file]); | |
return ( | |
<> | |
<FileUploader onFileLoad={setFile} /> | |
<Editor height="90vh" language="javascript" value={value} /> | |
</> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment