Spaces:
Sleeping
Sleeping
| import React, { createContext, useState, useCallback } from 'react'; | |
| export const LogContext = createContext(); | |
| export const LogProvider = ({ children }) => { | |
| const [logs, setLogs] = useState([]); | |
| const addLog = useCallback((message, level = 'INFO') => { | |
| const timestamp = new Date().toISOString(); | |
| const newLog = { timestamp, message, level }; | |
| setLogs(prevLogs => [...prevLogs, newLog]); | |
| }, []); | |
| return ( | |
| <LogContext.Provider value={{ logs, addLog }}> | |
| {children} | |
| </LogContext.Provider> | |
| ); | |
| }; | |