Skip to main content

Overview

The Mes component serves as a container for organizing and displaying payment items that belong to a specific month. It filters the payments based on whether they are monthly recurring or scheduled for the specific month, and renders each applicable payment as a Pago component.

Features

  • Month Header: Displays the month name
  • Smart Filtering: Shows only relevant payments (monthly or month-specific)
  • List Organization: Renders payments in an unordered list structure
  • Scalable Design: Handles any number of payment items

Location

src/components/Mes.jsx

Props

mes
string
required
The month identifier/name (e.g., “Enero”, “Febrero”, “Marzo”)This value is:
  • Displayed as the section header
  • Passed to each Pago component
  • Used for filtering which payments to display
pagos
array
required
Array of payment objects to be displayed in this monthEach payment object should contain:
  • nombre (string): Payment name/identifier (used as React key)
  • mensual (boolean): If true, payment appears in all months
  • meses (array, optional): Specific months where this payment applies

Filtering Logic

The component uses a conditional render to determine which payments to display:
(pago.mensual || pago.meses?.includes(mes))
A payment is shown if either:
  1. pago.mensual === true - Recurring monthly payment
  2. pago.meses array includes the current mes value
The optional chaining operator (?.) safely handles payments without a meses property.

Usage Example

Basic Usage

import { Mes } from './components/Mes'

function MonthlyView() {
  const pagos = [
    {
      nombre: 'Electricity',
      mensual: true  // Appears every month
    },
    {
      nombre: 'Insurance',
      mensual: false,
      meses: ['Enero', 'Julio']  // Only January and July
    },
    {
      nombre: 'Rent',
      mensual: true
    }
  ]
  
  return <Mes mes="Enero" pagos={pagos} />
}
In this example:
  • “Electricity” will show (mensual: true)
  • “Insurance” will show (meses includes “Enero”)
  • “Rent” will show (mensual: true)

Multiple Months

import { Mes } from './components/Mes'

function YearView() {
  const allPayments = [
    { nombre: 'Electricity', mensual: true },
    { nombre: 'Water', mensual: true },
    { nombre: 'Car Registration', meses: ['Marzo'] }
  ]
  
  const months = ['Enero', 'Febrero', 'Marzo']
  
  return (
    <div className="year-view">
      {months.map(month => (
        <Mes key={month} mes={month} pagos={allPayments} />
      ))}
    </div>
  )
}

Component Structure

The component renders:
<div className='mes'>
  <h2>{mes}</h2>           {/* Month header */}
  <ul>
    {/* Filtered Pago components */}
  </ul>
</div>

Key Prop

Each Pago component uses pago.nombre as its React key:
<Pago key={pago.nombre} pago={pago} mes={mes} />
Ensure that pago.nombre is unique within each month to avoid React key conflicts.

Payment Object Structure

Monthly Recurring Payment

{
  nombre: 'Electricity',
  mensual: true,
  // ... other payment properties
}

Specific Month Payment

{
  nombre: 'Quarterly Tax',
  mensual: false,
  meses: ['Marzo', 'Junio', 'Septiembre', 'Diciembre'],
  // ... other payment properties
}

Hybrid Example

{
  nombre: 'Special Payment',
  mensual: true,
  meses: ['Enero', 'Febrero'],  // meses is ignored when mensual is true
  // ... other payment properties
}
When mensual: true, the component displays the payment regardless of the meses array.

Rendering Behavior

Empty Month

If no payments match the filter criteria, the component renders an empty list:
<div className='mes'>
  <h2>Abril</h2>
  <ul>
    {/* Empty - no payments match */}
  </ul>
</div>

Full Month

With multiple matching payments:
<div className='mes'>
  <h2>Enero</h2>
  <ul>
    <Pago key="Rent" pago={rentObj} mes="Enero" />
    <Pago key="Electricity" pago={electricityObj} mes="Enero" />
    <Pago key="Internet" pago={internetObj} mes="Enero" />
  </ul>
</div>

Dependencies

  • Pago component - Renders individual payment items

Styling

The component uses the mes CSS class for the container. Styling should be defined in the application’s CSS files.

Common Patterns

Year View with All Months

const MONTHS = [
  'Enero', 'Febrero', 'Marzo', 'Abril',
  'Mayo', 'Junio', 'Julio', 'Agosto',
  'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'
]

function App() {
  const [pagos, setPagos] = useState([])
  
  return (
    <div className="app">
      {MONTHS.map(mes => (
        <Mes key={mes} mes={mes} pagos={pagos} />
      ))}
    </div>
  )
}

Source Code Reference

Component implementation at src/components/Mes.jsx:5-18 Filtering logic at src/components/Mes.jsx:11

Build docs developers (and LLMs) love