DEV Community

Discussion on: React Beginner Question Thread ⚛

 
dan_abramov profile image
Dan Abramov • Edited

Why not export a component that takes props? In your example, <Customer name="Dan" /> or <Customer name="Andrew" />. Then you can have different apps render the same component with different props.

Of course in practice you'd have more props, but you can also pass a whole object with them, e.g. <Customer brandData={{name: 'Andrew', color: 'red'}} />. If it’s too cumbersome to pass it down the tree to every component you can also use context for this.

The reason I dislike your solution is that you end up bundling all variations for every single deployment. So your bundle for a baby powder brand would also contain all the strings you use for a vodka brand. Not great.

Thread Thread
 
iamandrewluca profile image
Andrei Luca • Edited

Actually I looked into compiled sources and is not bundling all variations.
Thanks for your reply!

Thread Thread
 
dan_abramov profile image
Dan Abramov

Good to know! I guess webpack is smart enough to do the replacement earlier :-). This is still not a great future-proof approach because it relies on requires whereas the ecosystem has been moving to ES modules. It’s also much harder for any other tools to understand what’s going on in your modules.