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.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
Actually I looked into compiled sources and is not bundling all variations.
Thanks for your reply!
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
require
s 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.