DEV Community

Cover image for Don't use React imports like this. Use Wrapper Pattern instead
Nikola Perišić
Nikola Perišić

Posted on • Edited on

54 1 1 3 6

Don't use React imports like this. Use Wrapper Pattern instead

Updated version. Read on: https://medium.com/@perisicnikola37/dont-use-react-imports-like-this-use-wrapper-pattern-instead-b7a49b864ff4

Top comments (11)

Collapse
 
thraizz profile image
Aron Schüler
Comment hidden by post author
Collapse
 
manuel_fernandogallegoa profile image
manuel fernando gallego arias

Great to know, thanks Nikola.

Collapse
 
syed_salman_b127175252354 profile image
Comment hidden by post author
Collapse
 
perisicnikola37 profile image
Nikola Perišić

There are multiple benefits:

  • Developers in the codebase know what to use and import -With a wrapper, developers don’t need to think about the best way to import a library each time. They just use the predefined optimized wrapper.
  • Avoiding Redundant Imports - If every component manually imports specific thing from lodash for example, there’s a risk that different components may import some different parts of the library.
  • Ease of Maintenance - If a library updates its exports or introduces a more optimized way to import, you only need to update the wrapper file instead of refactoring every single component.
Collapse
 
thanksboss profile image
Andrew K • Edited
Comment hidden by post author
Collapse
 
perisicnikola37 profile image
Nikola Perišić • Edited

yep, this is still the old version
check new one on: medium.com/@perisicnikola37/dont-u...

Collapse
 
thanksboss profile image
Andrew K

Yeah, this makes more sense now.

Collapse
 
lamualfa profile image
Laode Muhammad Al Fatih
Comment hidden by post author
Collapse
 
perisicnikola37 profile image
Nikola Perišić

Well, many people who liked this article on Medium would argue with you xD

Collapse
 
diginja profile image
Guyllaume Doyer
Comment hidden by post author
Collapse
 
perisicnikola37 profile image
Nikola Perišić

Some comments have been hidden by the post's author - find out more