DEV Community

Bret
Bret

Posted on

2

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.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs