I'm working on an application that presents a list of tasks. When a user clicks on a task, it should present a form so that the user can update the status of that task. There are different types of tasks, however, and the correct form needs to be presented based on the task type. Each task type has a task definition with a field that identifies the form required for that task. When someone clicks on a task, the task object, including the task formComponent is passed to the formWrapper component. Each form component is in a JSX file and they are all exported as TaskForm.
I need to select the component based on the task definition. I thought I could accomplish this with react.Lazy by doing the following:
In the formWrapper's componentDidMount():
// Store the path to the required JSX file in the state.
this.setState( {formFile: '../Processes/'+this.state.task.formComponent} );
Then in formWrapper's render():
TaskForm = React.lazy(() => import(this.state.formFile));
return (
<Suspense fallback={<div>Loading...</div>}>
<TaskForm task={this.props.task} />
</Suspense>
When I launch node.js, however it throws the warning "Critical dependency: the request of a dependency is an expression" and the form fails to load.
Am I even close to being on the right track? I can't statically define the forms. There are several of them and they are subject to change.