Last active
July 17, 2020 20:43
-
-
Save DZuz14/5eabac4cb1ec15aac5bc3866fd9b1a48 to your computer and use it in GitHub Desktop.
Accordion with state and function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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