Next.js Discord

Discord Forum

How can i store a component in database as string

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
{
    type: "p",
    content: "",
  },
  {
    type: "title",
    content: "Multi-Line Chart",
  },
  {
    type: "component",
    content: '@/components/documents/chart-making/MultiLineChart',
  }, 


I have content like this and i store this content in database but how can i import a component as render in my screen. I tried next/dynamic but it doesnt work. How can i solve this problem? Could you please help me ?

4 Replies

Transvaal lionOP
import dynamic from "next/dynamic";
import React, { Suspense } from "react";

const DynamicComponent = ({ route, ...props }: { route: string }) => {
  const Component = dynamic(() => import(route), {
    ssr: false,
  });

  return (
    <Suspense fallback={<></>}>
      <Component {...props} />
    </Suspense>
  );
};

export default DynamicComponent;


I tried this
Error: Cannot find module '@/components/documents/chart-making/LineChartComponent'
American Chinchilla
Why are you trying to store a component in a db? Thats a red flag
also is the path correct for @/... ?