import React, { useEffect, useState } from 'react';
const ConsoleLog = () => {
const [logs, setLogs] = useState([]);
useEffect(() => {
const consoleLog = console.log;
console.log = (message) => {
setLogs((prevLogs) => [...prevLogs, message]);
consoleLog.apply(console, arguments);
};
}, []);
return (
<div>
<button onClick={() => setLogs([])}>Clear logs</button>
{logs.map((log, index) => (
<p key={index}>{log}</p>
))}
</div>
);
};
export default ConsoleLog;