Last active
November 30, 2023 17:23
-
-
Save andria-dev/ded23783b18b5f6e00f796572cd324ab to your computer and use it in GitHub Desktop.
React Logging Examples
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
// Same as useEffect in <App> but abstracted | |
function useLog(...values) { | |
useEffect(() => { | |
console.log(...values) | |
}, values) | |
} | |
function App() { | |
const [todos, setTodos] = useState([]); | |
// Logs on every update. | |
console.log(todos); | |
// Logs on every change to todos. | |
useEffect(() => { | |
console.log(todos); | |
}, [todos]); | |
// Abstracted | |
useLog(todos); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment