Created
January 18, 2023 21:48
-
-
Save imhalid/abc87e71523c0446245f1ab24d8cb2d5 to your computer and use it in GitHub Desktop.
Sending console output into an HTML element
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 } from 'react' | |
const ConsoleLog = () => { | |
useEffect(() => { | |
if (typeof console !== 'undefined') { | |
if (typeof console.log !== 'undefined') { | |
console.olog = console.log | |
} else { | |
console.olog = function () {} | |
} | |
console.log = function (message) { | |
let consolelog = document.querySelector('#consolelog') | |
let p = document.createElement('p') | |
p.innerHTML = message | |
consolelog.appendChild(p) | |
} | |
console.error = console.debug = console.info = console.log | |
} | |
}, []) | |
return <p id='consolelog'></p> | |
} | |
export default ConsoleLog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment