Getting started with integration using React

Please fill out as many of the following questions as possible so we can help you promptly! If you don’t know how to answer or it does not apply, feel free to remove it or leave it blank.

Builder content link

Builder public api key
go to Builder.io: Drag and drop Visual CMS and copy your PUBLIC api key

What are you trying to accomplish
Use the integration tutorial’ of React code in VSCode that flag “async” as "un

Screenshots or video link
image

Screenshots of your issue, or even better a link to a video of what is happening or what you are trying to accomplish. We love using loom for that sort of thing
image

Code stack you are integrating Builder with
react

Reproducible code example
If you are having integration errors, please link to codesandbox or copy and paste your problematic code here. The more detail the better!

import { BuilderComponent, builder, useIsPreviewing } from ‘@builder.io/react’;

// Put your API key here
builder.init(‘I removed my API key’)

// set whether you’re using the Visual Editor,
// whether there are changes,
// and render the content if found
export default function CatchAllRoute() {
const isPreviewingInBuilder = useIsPreviewing();
const [notFound, setNotFound] = useState(false);
const [content, setContent] = useState(null);

useEffect( () => {
async fetchContent {
const content = await builder.get(‘page’, {
url: location.pathname
}).promise();

  setContent(content);
  setNotFound(!content);
}

}, [location.pathname]);
// if no page is found, return a 404 page
if (notFound && !isPreviewingInBuilder) {
return
}

// return the page when found
return (
<>

{content?.data.title}

{/* Render the Builder page */}

</>
);
}

Hi George,

Thank you so much for reaching out! I’d gladly love to assist.

It looks like in the code it is missing calling the fetchContent function from within useEffect() hook. I’ve linked a CodeSandbox link with a working React integration for reference: https://codesandbox.io/s/builder-react-integrating-pages-2-kp19hb?file=/ src/App.js:0-1220

Please let me know if this helps. If this doesn’t work, please share a link to your content and we can take a further look.

Thanks.

Screen Shot 2022-10-17 at 1.22.16 PM

It works … thank you!