From 45b90c4c33cdce6318b1258e7c3434dae682f653 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sun, 6 Sep 2020 13:55:12 +0300 Subject: [PATCH] Update Accordion --- snippets/Accordion.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/snippets/Accordion.md b/snippets/Accordion.md index 51154f6cd..5948fc5ef 100644 --- a/snippets/Accordion.md +++ b/snippets/Accordion.md @@ -5,15 +5,15 @@ tags: components,children,state,advanced Renders an accordion menu with multiple collapsible content components. -- Define an `AccordionItem` component, pass it to the `Accordion` and remove unnecessary nodes expect for `AccordionItem` by identifying the function's name in `props.children`. -- Each `AccordionItem` component renders a `
- {props.children} + {children}
); -} +}; -function Accordion(props) { - const [bindIndex, setBindIndex] = React.useState(props.defaultIndex); +const Accordion = ({ defaultIndex, onItemClick, children }) => { + const [bindIndex, setBindIndex] = React.useState(defaultIndex); const changeItem = itemIndex => { - if (typeof props.onItemClick === 'function') props.onItemClick(itemIndex); + if (typeof onItemClick === 'function') onItemClick(itemIndex); if (itemIndex !== bindIndex) setBindIndex(itemIndex); }; - const items = props.children.filter(item => item.type.name === 'AccordionItem'); + const items = children.filter(item => item.type.name === 'AccordionItem'); return (
@@ -64,7 +64,7 @@ function Accordion(props) { ))}
); -} +}; ``` ```jsx