I have an application that runs in 3 different countries (something close to an e-commerce). Each country has a development team that can change some specific component to fit the needs. I'm thinking about passing the components through context, but how to pick the Form-US or the Form-UK, for example? (Thinking that importing dynamically it's not possible in React)
My App.js
import React from 'react'
import UserInput from './common/UserInput'
class App extends React.Component {
getChildContext () {
return {
input: UserInput
}
}
render () {
return (
<div>
{this.props.children}
</div>
)
}
}
App.childContextTypes = {
input: React.PropTypes.object
}
export default App
And I pick the component when needed like that:
render () {
const Input = this.context.input
return (
<Input placeholder='Input Test'/>
)
}
That Works just fine, but its that a good practice? It's there a better way to do it and how can I add a component with a specific name to that structure?
require('Component-${COUNTRY}')instead of importing all possible childs?Inputand then always have the parent useInput.