contentful / experience-builder

https://www.contentful.com/developers/docs/experiences/what-are-experiences/
MIT License
5 stars 1 forks source link

feat: add detachExperienceStyles function [SPA-2049] #579

Closed Spring3 closed 2 weeks ago

Spring3 commented 3 weeks ago

Purpose

This function supports:

Approach

Read the comments in the code

Usage

import { ExperienceRoot, fetchBySlug, detachExperienceStyles } from '@contentful/experience-builder-sdk-react';

export const getServerSideProps = () => {
    const experience = fetchBySlug('...');

   let styles = '';

   if (experience) {
       styles = detachExperienceStyles(experience);
   }

   return {
       props: {
           styles,
           experienceJSON: JSON.stringify(expereince)
       }
   }
}

export const Page = ({ styles, experienceJSON }) => {
    const experience = createExperience(experienceJSON);

    return (
       <>
          <style>{styles}</style>
          <ExperienceRoot experience={experience} />
       </>
    );
}

TODO

vercel[bot] commented 3 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
experience-builder-test-app ✅ Ready (Inspect) Visit Preview Apr 30, 2024 9:17am