I build a “dynamic” navigation for which i can define the links in builder.io,
(see below for the complete code),
but when i edit the data in builder.io, the preview does not update until i publish and reload.
Builder content link
Builder public api key
2e78205c84e742f38c54bf8bcf540cf9
What are you trying to accomplish
live edit / visually edit navigation links
Screenshots or video link
https://streamable.com/0lsdh0
Code stack you are integrating Builder with
Qwik
Reproducible code example
import { Resource, component$, useResource$ } from "@builder.io/qwik";
import { getAllContent } from "@builder.io/sdk-qwik";
import { NavLink } from "../nav-link/nav-link";
interface LinkDocument {
data: {
label: {
Default: string;
};
href: {
Default: string;
};
order: number;
};
}
interface Props {
linkModel: string;
}
export const DynamicLinkList = component$((props: Props) => {
const linksResource = useResource$(() =>
getAllContent({
model: props.linkModel,
apiKey: import.meta.env.PUBLIC_BUILDER_API_KEY,
}).then((links) => {
(links as {results: LinkDocument[]}).results.sort((a, b) => a.data.order - b.data.order);
return links;
}),
);
return (
<Resource
value={linksResource}
onPending={() => <>Loading...</>}
onRejected={(error) => <>Error: {error.message}</>}
onResolved={(links) => (
<ul>
{(links as {results: LinkDocument[]}).results.map((link) => (
<li
key={`link-${link.data.href.Default}-${link.data.label.Default}`}
>
<NavLink href={link.data.href.Default} activeClass="active">
{link.data.label.Default}
</NavLink>
</li>
))}
</ul>
)}
/>
);
});