Skip to content

Instantly share code, notes, and snippets.

@thesabbir
Created May 9, 2021 16:57
Show Gist options
  • Save thesabbir/369a3d79a20941d2100363f81e93fe57 to your computer and use it in GitHub Desktop.
Save thesabbir/369a3d79a20941d2100363f81e93fe57 to your computer and use it in GitHub Desktop.
Editorjs Nested List render
import React from "react";
const NestedListRenderer = ({ data }) => {
const ListType = ({ children, style }) =>
style === "unordered" ? <ul>{children}</ul> : <ol>{children}</ol>;
const renderWalk = (items) =>
!!items.length && (
<ListType style={data.style}>
{items.map((item) => (
<React.Fragment key={item.content}>
<li>{item.content}</li>
{renderWalk(item.items)}
</React.Fragment>
))}
</ListType>
);
return <div className="nested-list"> {renderWalk(data.items)}</div>;
};
export default NestedListRenderer;
.nested-list ol {
counter-reset: item
}
.nested-list li {
display: block
}
.nested-list li:before {
content: counters(item, ".") " ";
counter-increment: item
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment