DEV Community

Discussion on: About React code structure

Collapse
 
dance2die profile image
Sung M. Kim

For Function Components (FC) I prefer named functions

const Test () => {}
// or 
function Test() {}

export default Test
Enter fullscreen mode Exit fullscreen mode

to export default () => {} syntax because of readability.

When you move your components around, say rename the file from Test.jsx to index.jsx for some reason, you have to dig thru code to see what it is for others.

You can use Class Components (CC) for handling error boundaries or to use life cycle methods not provided by Hooks (componentDidCatch & getDerivedStateFromError). CC isn't going away
but my personal opinion is that, FC with hooks seems to be where it's going (and I found FC w/ hooks much easier to write/reason about with shorter code).

Collapse
 
gundogduyakici profile image
Gündoğdu Yakıcı

Thank you for informing me