Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!