Skip to content

Instantly share code, notes, and snippets.

@andria-dev
Last active November 30, 2023 17:23
Show Gist options
  • Save andria-dev/ded23783b18b5f6e00f796572cd324ab to your computer and use it in GitHub Desktop.
Save andria-dev/ded23783b18b5f6e00f796572cd324ab to your computer and use it in GitHub Desktop.
React Logging Examples
// 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