React is incredibly powerful, but mastering it means going beyond the basics and learning some lesser-known tricks to streamline development. Hereβ...
For further actions, you may consider blocking this person and/or reporting abuse
Yes this one :
Export Components with Named Exports for Better Import Control
My senior also pointed out me to use like this as explained in
19
tip instead of export default.What's the reason behind using this and why not I prefer export deafault componentA.
@paxnw ,
Using named exports instead of default exports provides better control and clarity when importing components.
With named exports, you can import multiple components from a single module, which helps avoid naming collisions and makes it clear what is being imported.
This practice also enhances code readability and maintainability by explicitly defining what components are available for use, making it easier to track dependencies in larger codebases.
In 12 what is the benefit of prop types over using Interfaces. Haven't seen this before so I was wondering.
@dasheck0 ,
In React (if I talk about JS based), PropTypes allow runtime type checking for props, catching errors during execution, whereas TypeScript interfaces provide static type checking at compile time, which can prevent errors earlier.
I see. Thanks for clarifying
Personally I prefer TypeScript interfaces over the older PropTypes.
Yes me too, but for javascript based React project it's very handy. @joels
Destructuring props directly in the function parameters is my favorite approachβit enhances code readability significantly. While some people argue that it's too common to be noteworthy, I disagree. Previously, I worked on a React project with code that was messy: excessive prop drilling and constant references like
props.name
andprops.user.address.pincode
. Dealing with this was frustrating, which is why destructuring has become my go-to.Exactly @john12 !!
Prefer clsx over classnames. classnames is ~3 times bigger than clsx.
npm trends
Nice
Thanks
I prefer
classcat
overclassnames
package for cases where I don't want to use interpolated strings. I saw some performance comparisons some time ago and stuck with it ever since.hbb