Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
Trying to make multiple checkboxes mapped from an array. How do I check the single value from an array of checkboxes?

I have a React component of multiple plan Types and each plan type has either monthly or annual subscription. How can I select only one (monthly or annual) from only 1 plan at a time. I am creating the planTypes from an array of planTypes

import React, { useState } from "react";
import "./styles.css";
import Checkbox from "@material-ui/core/Checkbox";

export default function App() {
  const initialState = {
    Essentials: {
      monthly: false,
      annually: false
    },
    Pro: {
      monthly: false,
      annually: false
    },
    ProPlus: {
      monthly: false,
      annually: false
    }
  };

  const plans = [
    { planName: "free", cost: "$3" },
    { planName: "premium", cost: "$30" },
    { planName: "premiumPlus", cost: "$300" }
  ];

  const [checkboxVal, setCheckboxVal] = useState(initialState);
  const [selectedPlan, setSelectedPlan] = useState("");
  return (
    <div className="App">
      {plans.map((item, idx) => {
        console.log(item, "here");
        return (
          <div
            style={{
              width: "300px",
              height: "300px",
              border: "1px solid black"
            }}
          >
            <div>{item.planName}</div>
            <br />
            monthly
            <Checkbox
            // checked={}
            // onChange={}
            // name={`${item.planName}-monthly`}
            />
            <br />
            Annually
            <Checkbox
            // checked={}
            // onChange={}
            // name={`${item.planName}-annually`}
            />
          </div>
        );
      })}
    </div>
  );
}

demo link: https://codesandbox.io/s/goofy-diffie-suten?file=/src/App.js:0-1442

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda