import React, { useState, useEffect } from 'react' const { apiFetch } = wp; import Masonry from 'react-masonry-component'; const Sections = () => { const [isLoading, setISLoading] = useState(false) const [sections, setSections] = useState([]); useEffect(() => { wp.apiFetch({ method: 'GET', path: '/blockspare/v1/layouts/all?filter=allowed', }).then(async (components) => { const sections = []; Object.values(components).forEach(function (item) { if ('section' === item.type) { sections.push(item); } }) setISLoading(true) setSections(sections) }) }, []) const masonryOptions = { transitionDuration: 0, percentPosition: true, }; return (
{isLoading ? {sections && sections.map((item, i) => { const nameInLowerCase = item.name.toLowerCase(); const imageName = nameInLowerCase.replace(/\s+/g, '-'); const folderName = item.imagePath return (
{ item.content === 'https://www.blockspare.com/' && pro }
{item.name}
) }) }
:
}
) } export default Sections