Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Last active July 17, 2020 20:43
Show Gist options
  • Save DZuz14/5eabac4cb1ec15aac5bc3866fd9b1a48 to your computer and use it in GitHub Desktop.
Save DZuz14/5eabac4cb1ec15aac5bc3866fd9b1a48 to your computer and use it in GitHub Desktop.
Accordion with state and function
import React, { useState } from 'react'
import Collapsed from './Collapsed'
import Expanded from './Expanded'
const Accordion = ({ children }) => {
const [open, setOpen] = useState('')
const handleOpen = (e) => {
const id = e.target.getAttribute('data-id')
id === open ? setOpen('') : setOpen(id)
}
return <div>{children}</div>
}
Accordion.Collapsed = Collapsed
Accordion.Expanded = Expanded
Accordion.Item = ({ children }) => children
export default Accordion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment