DEV Community

Discussion on: Most common design patterns for Front-End with JavaScript (Real-world examples)

Collapse
 
hashcode01 profile image
Hash

How does this look ?

// React components section
import React from "react";
import UserForm  from "./userForm";
import AdminForm from "./adminForm";
import GuestForm from "./guestForm";

/*
* This object literal will help to encapsulate all the forms that could we have.
*/
const FormsManage = {
  user : UserForm,
  admin: AdminForm,
  guest:GuestForm
};

/*
* Main form component
*/
const Form = (props) => {
  // here we are getting the form by type
  const UserForm = FormsManage[props.type];
  return <UserForm  {...props} />
};
export default Form;

Enter fullscreen mode Exit fullscreen mode
Collapse
 
lukocastillo profile image
Luis Castillo

Awesome bro, looks great!