Componentes reutilizables en React para apps más rápidas
Clase 6 de 27 • Curso de lanzamiento y monetización de webs con Lovable
Resumen
Building with reusable React components inside Lovable keeps your app fast, consistent, and easy to iterate. By sharing the same UI and logic across pages—like a single File Drop Zone used on the landing page and the dashboard—you avoid duplicated work and reduce codebase bloat while keeping design changes synchronized everywhere.
Why reuse components in React and Lovable?
Reusing components means one source of truth for UI and behavior. A component is a self-contained piece of UI; for instance, a drop zone can bundle a header, the drag-and-drop logic, and buttons into one unit stored in the components folder. When the same component is imported in multiple pages, any edit propagates automatically.
- One component, many places. The same Drop Zone appears on the welcome page and the dashboard.
- Consistent by design. Edit once; changes reflect across the app.
- Less code, fewer bugs. Reuse cuts duplication and prevents drift between versions.
- Faster iterations in Lovable. Smaller, shared components make edits safer and quicker.
What is a component in React?
- A focused piece of UI with its own logic and structure.
- Composed of smaller parts: header, drop logic, buttons.
- Lives in a dedicated components folder for easy reuse.
Where does reuse matter most?
- Landing page hero: quick try with 1–2 photos for free.
- Dashboard: advanced features like the photo gallery and batch renaming.
- Any page needing the same UX and visual consistency.
How to implement and manage the drop zone component?
The Drop Zone used for uploading photos is embedded on the landing page hero and reused on the dashboard. Even if the first render “doesn’t look great,” it proves the point: reuse first, refine styling once—everywhere. This avoids creating similar components repeatedly and keeps Lovable effective at scoped edits rather than sweeping changes.
- Edit once, update everywhere. Design tweaks on the homepage update the dashboard too.
- Prevent bloat. Prefer importing the existing Drop Zone over creating new files.
- Name matters. Refer to the exact component name (e.g., File Drop Zone component) when prompting.
How to prompt Lovable effectively?
- Be explicit: “Using our drop zone component, put a copy on the hero of the landing page.”
- Reference the exact component name to avoid accidental duplicates.
- Specify the location (e.g., hero, welcome page, dashboard) to speed up changes.
How to keep components fast and maintainable?
- Keep them small. If a component approaches or exceeds ~300 lines, ask to refactor into smaller, organized components.
- Use clear prompts. “Refactor the drop zone into smaller and more organized components.”
- Know your inventory. Use Open Code → Components folder to see what exists (e.g., weather widget) and reuse instead of recreating.
- Reduce cognitive load. Fewer, smaller components simplify reviews and testing.
How does planning and a design system speed up development?
Starting with a plan, a design system, and a theme accelerates delivery and cuts rework. Consistent styles let components look right the first time and stay aligned as the app grows. Bringing in quality building blocks (e.g., components discovered on 21st Dev) adds polish, while your own theme ensures the look and feel match the target client or customer.
- Plan upfront. Sketch a flow in a Mermaid diagram or on paper to guide builds.
- Adopt a design system. Enforce consistent spacing, colors, and components.
- Define a theme. Set tone and style for your audience early.
- Stay consistent. The entire application benefits from shared decisions.
What component would you reuse next in your app? Share your approach and the prompts you’d try to keep your codebase lean and consistent.