Update snippet formatting
This commit is contained in:
@ -7,7 +7,7 @@ Renders a tree view of a JSON object or array with collapsible content.
|
||||
|
||||
- Use object destructuring to set defaults for certain props.
|
||||
- Use the value of the `toggled` prop to determine the initial state of the content (collapsed/expanded).
|
||||
- Use the `React.setState()` hook to create the `isToggled` state variable and give it the value of the `toggled` prop initially.
|
||||
- Use the `React.useState()` hook to create the `isToggled` state variable and give it the value of the `toggled` prop initially.
|
||||
- Return a `<div>` to wrap the contents of the component and the `<span>` element, used to alter the component's `isToggled` state.
|
||||
- Determine the appearance of the component, based on `isParentToggled`, `isToggled`, `name` and `Array.isArray()` on `data`.
|
||||
- For each child in `data`, determine if it is an object or array and recursively render a sub-tree.
|
||||
@ -50,14 +50,14 @@ div.tree-element:before {
|
||||
```
|
||||
|
||||
```jsx
|
||||
function TreeView({
|
||||
const TreeView = ({
|
||||
data,
|
||||
toggled = true,
|
||||
name = null,
|
||||
isLast = true,
|
||||
isChildElement = false,
|
||||
isParentToggled = true
|
||||
}) {
|
||||
}) => {
|
||||
const [isToggled, setIsToggled] = React.useState(toggled);
|
||||
|
||||
return (
|
||||
@ -96,11 +96,11 @@ function TreeView({
|
||||
{!isLast ? ',' : ''}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
```jsx
|
||||
let data = {
|
||||
const data = {
|
||||
lorem: {
|
||||
ipsum: 'dolor sit',
|
||||
amet: {
|
||||
|
||||
Reference in New Issue
Block a user