DEV Community

Bret
Bret

Posted on

Should a custom React Hook be in 2 files? Also... should a reusable component be in one file?

When you make a react hook, should it be in one file or 2? Such as news.JS and setNews.JS?
Also, when you make a reusable component such as a “to do”, do you want the info in the same file as the template “render or return”?

Top comments (1)

Collapse
 
0916dhkim profile image
Danny Kim

I would name the custom hook module useNews.js (one file). That way, it is less confusing where to import the hook. For components, I prefer putting everything inside one module (e.g. Todo.jsx), as long as it stays under 500 lines of code.