Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
To run the project based on the provided package.json, follow these steps: Step 1: Clone the Project First, clone the project from the GitHub repository. If you already have the project locally, you can skip this step. Use the following command in your terminal: bash git clone https://github.com/your-username/vite-react-typescript-starter.git Replace https://github.com/your-username/vite-react-typescript-starter.git with the actual URL of your repository. Step 2: Navigate to the Project Directory Navigate into the project directory: bash cd vite-react-typescript-starter Step 3: Install Dependencies Install all dependencies listed in package.json: bash npm install # or yarn install Step 4: Run the Project Now, you can run the project using the following commands: Development Mode To start the development server: bash npm run dev # or yarn dev This will start the Vite development server, and you can view your application at the address shown in the terminal output (usually http://localhost:5173/). Build the Project To build the project for production: bash npm run build # or yarn build Preview the Built Project To preview the built project: bash npm run preview # or yarn preview This command will serve the built project, allowing you to test it as if it were deployed. Lint the Project To run ESLint on the project: bash npm run lint # or yarn lint Approach and Challenges Approach: To build a dynamic form generator, I employed a recursive approach using React. The DynamicForm component takes a JSON schema as input and renders form fields based on this schema. The schema supports various field types such as text inputs, select dropdowns, checkboxes, and nested sections. I utilized React hooks (useState) for managing form data and validation errors. The form submission is handled by validating all fields and then calling a callback function with the submitted data. Challenges: Recursive Rendering: Handling nested sections required careful implementation to ensure proper recursion. Although the schema is flat within sections, managing recursive calls for nested fields was a challenge. State Management: Managing state for dynamic fields was complex. Ensuring that each field's value and validation status were correctly updated in the state required careful handling of state updates. Validation: Implementing validation rules based on the schema was challenging, especially for different field types. Ensuring that validation messages were correctly displayed and updated was crucial. Styling: While basic styling was applied using inline styles, integrating a CSS framework like Tailwind CSS would be beneficial for more robust and responsive styling. Type Safety (in TypeScript version): Ensuring type safety by defining types for the schema and form data helped maintain code clarity but required careful type definitions to accommodate dynamic schema structures. Overall, the approach allowed for a flexible and reusable form component, but managing state and validation dynamically presented the most significant challenges.