-
Notifications
You must be signed in to change notification settings - Fork 161
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
02a6c8b
commit b3f51de
Showing
8 changed files
with
141 additions
and
197 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
import React, { useState } from 'react'; | ||
|
||
const CodeExecutor: React.FC = () => { | ||
const [code, setCode] = useState<string>(''); | ||
const [output, setOutput] = useState<string>(''); | ||
const executeCode = () => { | ||
try { | ||
const result = eval(` | ||
const [code, setCode] = useState<string>(''); | ||
const [output, setOutput] = useState<string>(''); | ||
|
||
const executeCode = () => { | ||
try { | ||
const result = eval(` | ||
(function() { | ||
${code} | ||
})() | ||
`); | ||
setOutput(String(result)); | ||
} catch (error) { | ||
setOutput(`Erreur : ${(error as Error).message}`); | ||
} | ||
}; | ||
setOutput(String(result)); | ||
} catch (error) { | ||
setOutput(`Erreur : ${(error as Error).message}`); | ||
} | ||
}; | ||
|
||
return ( | ||
<div style={{ padding: '20px', maxWidth: '600px', margin: '0 auto' }}> | ||
<h2>Execute your JavaScript Code</h2> | ||
<textarea | ||
value={code} | ||
onChange={(e) => setCode(e.target.value)} | ||
placeholder="Write your JavaScript code here..." | ||
rows={10} | ||
style={{ width: '100%', marginBottom: '10px' }} | ||
></textarea> | ||
<button onClick={executeCode} style={{ padding: '10px 20px' }}> | ||
Execute the code | ||
</button> | ||
<div style={{ marginTop: '20px', padding: '10px', backgroundColor: '#f5f5f5' }}> | ||
<h3>Result :</h3> | ||
<pre>{output}</pre> | ||
</div> | ||
</div> | ||
); | ||
return ( | ||
<div style={{ padding: '20px', maxWidth: '600px', margin: '0 auto' }}> | ||
<h2>Execute your JavaScript Code</h2> | ||
<textarea | ||
value={code} | ||
onChange={e => setCode(e.target.value)} | ||
placeholder="Write your JavaScript code here..." | ||
rows={10} | ||
style={{ width: '100%', marginBottom: '10px' }} | ||
></textarea> | ||
<button onClick={executeCode} style={{ padding: '10px 20px' }}> | ||
Execute the code | ||
</button> | ||
<div style={{ marginTop: '20px', padding: '10px', backgroundColor: '#f5f5f5' }}> | ||
<h3>Result :</h3> | ||
<pre>{output}</pre> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CodeExecutor; |
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
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
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