shuding/tilg là dự án Frontend trên GitHub, viết chủ yếu bằng TypeScript, với 2.2k sao. A magical React Hook that helps you debug components.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Tiny Logger is a magical React Hook to help you debug your components.
You can quickly try out the demo.
Table of Contents
Installation
Features
Lifecycle Events (What)
Component Name and Props (Who)
Debug Message (Why)
What Has Changed? (Why)
Quick Logs (Why)
Advanced Features
Markdown
Return Original Value
Auto Deduplication
CLI Support
FAQ & Caveats
Installation
The package is released as tilg, use:
npm i tilg
to install it with npm. Or you can choose another package manager.
Features
1. Lifecycle Events (What)
Simply insert the useTilg() hook into the component, and it will log the render, mount, unmount events in the console:
import useTilg from 'tilg'
function MyButton() {
useTilg()
return <button>Click me</button>
}
Logs of render and mount events.
2. Component Name and Props (Who)
You might noticed that it also displays the name and props of the component, which is very helpful for debugging.
import useTilg from 'tilg'
function MyButton({ text }) {
useTilg()
return <button>{text}</button>
}
function Title({ children }) {
useTilg()
return <h1>{children}</h1>
}
export default function Page() {
return (
<>
<Title>Welcome!</Title>
<MyButton text='foo' />
<MyButton text='bar' />
</>
)
}
When there’re multiple elements of the same component being rendered, it adds a counter <MyButton/> (2) for distinguishing so you know who is logging the information:
Information of the logged components.
3. Debug Message (Why)
Another critical thing is to know why does a component re-renders. useTilg gives you a simple but powerful API for this:
import { useState } from 'react'
import useTilg from 'tilg'
function Counter() {
const [count, setCount] = useState(0)
useTilg()`count = ${count}`
return <button onClick={() => setCount(count + 1)}>{count}</button>
}
When appending a template literal to the useTilg() call, it will also be displayed as the debug message:
useTilg()`count = ${count}`
Logs of “count = ?”.
You can know where the message is from, too:
Trace of the message and a link to the code location.
4. What Has Changed? (Why)
Something troubles me a lot when debugging a component is, it’s sometimes hard to know which state has changed and triggered a re-render. useTilg tracks all the arguments in the debug message and tells you which one has changed since the previous render:
The useTilg() hook also returns its first argument, or the first value in the template if specified, so you can quickly debug something in-place by wrapping it with useTilg():
Is it safe to ship code with useTilg to production?
Although useTilg() does nothing in a production build (process.env.NODE_ENV === 'production') but only an empty function, I encourge you to remove the hook from the source code after finishing the development of your app.
How do you implement this hook? What can I learn from the code?
It is very hacky. Don't do the same thing especially try it in production, or you will be fired.
Why not design the API as useTilg`message`?
Then it will not be identified as a hook, React Refresh and HMR will not work correctly.
shuding/tilg thuộc nhóm Frontend trên TopGit, cùng 4 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về shuding/tilg ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/shuding/tilg là nguồn chính thức.
shuding/tilg có bao nhiêu sao?
shuding/tilg có 2.2k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/shuding/tilg. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
shuding/tilg có những chủ đề gì?
GitHub topics của shuding/tilg: "debug", "logger", "react", "react-hooks". TopGit xếp repo vào nhóm Frontend.
shuding/tilg có phải mã nguồn mở không?
Có — shuding/tilg phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/shuding/tilg.
shuding/tilg có trang demo không?
Dự án có trang chủ ở https://codesandbox.io/s/usetilg-3kdtz8?file=/src/App.js:274-359. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
shuding/tilg còn đang phát triển không?
Commit gần nhất trên shuding/tilg là 3.9 năm trước (theo timestamp GitHub). Repo có 22 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
tilg có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về tilg.