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

338
Views
How to store Chakra-UI CheckboxGroup values in Firebase (React JS)

I am trying to store Chakra-UI's CheckboxGroup values in Firebase as a string of multiple elements. However, in the code I am using (below) I only get stored the last value selected. In other words, if I selected 'Valor1' and then 'Valor3', for example, 'Valor3' would be the only information stored in the corresponding Firebase string. I believe this is because of how onChange is defined, but even though I have tried several modifications I don't know how to fix it.

Code:

import {useState} from 'react'
import {useRouter} from 'next/router'
import axios from 'axios'
import {
  Box,
  FormControl,
  FormLabel,
  FormErrorMessage,
  FormHelperText,
  Button,
  Checkbox,
  CheckboxGroup,
  HStack,
} from '@chakra-ui/react'
import {Container} from '../components'

const Post = () => {
  const router = useRouter()
  const [content, setContent] = useState({
    cbox:'',
  })

  const onChange = e => {
    const {value, name} = e.target
    setContent(prevState => ({...prevState, [name]: value}))
  }

  const marginBetweenElements = 4

  return (
    <Container>
      <Box my={10} bgColor="white" p={6} borderRadius="md">
        <FormControl id="cbox" mb={marginBetweenElements} as="fieldset" isRequired>
          <FormLabel as="legend">CheckboxGroup test</FormLabel>
          <CheckboxGroup onChange={onChange} variant="filled">
            <HStack spacing="24px">
              <Checkbox type="text" name="cbox" value="Valor1">Valor1</Checkbox>
              <Checkbox type="text" name="cbox" value="Valor2">Valor2</Checkbox>
              <Checkbox type="text" name="cbox" value="Valor3">Valor3</Checkbox>
              <Checkbox type="text" name="cbox" value="Valor4">Valor4</Checkbox>
            </HStack>
          </CheckboxGroup>
        </FormControl>
        <Button onClick={onSubmit} mt={5}>
          Submit
        </Button>
      </Box>
    </Container>
  )
}

export default Post
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!