Next.js Discord

Discord Forum

How to store page in database?

Unanswered
mяvи posted this in #help-forum
Open in Discord
I am currently working on a project, and I am trying to implement a feature where users can design their own page in a dashboard, which is then displayed under "domain.com/user". I have already created a dynamic page [user] for this.

Now I'm wondering how to save this page so that the correct page is called depending on the username.

1 Reply

@mяvи I am currently working on a project, and I am trying to implement a feature where users can design their own page in a dashboard, which is then displayed under "domain.com/user". I have already created a dynamic page [user] for this. Now I'm wondering how to save this page so that the correct page is called depending on the username.
you need to have a common data format that represents the user page. usually it is json. for example, if you use Slate.js for the page editor that your users use, a page might look something like this

[
  {
    type: 'paragraph',
    children: [
      { text: 'This is editable ' },
      { text: 'rich', bold: true },
      { text: ' text, ' },
      { text: 'much', italic: true },
      { text: ' better than a ' },
      { text: '<textarea>', code: true },
      { text: '!' },
    ],
  },
  {
    type: 'paragraph',
    children: [
      {
        text: "Since it's rich text, you can do things like turn a selection of text ",
      },
      { text: 'bold', bold: true },
      {
        text: ', or add a semantically rendered block quote in the middle of the page, like this:',
      },
    ],
  },
  {
    type: 'block-quote',
    children: [{ text: 'A wise quote.' }],
  },
  {
    type: 'paragraph',
    align: 'center',
    children: [{ text: 'Try it out for yourself!' }],
  },
]


then you just save this json into the database. and inside [user], you fetch this json and render the page based on this json.