reactjsdraftjsdraft-js-plugins

Draft-js better way to save and retrive content form MySql


I use draft-js with some plugins as editor in a reactjs app.

I'm looking for a good way to store data on db and retrieve that data.

I think that the better solutions is to save data in two different format:

In my post I have:

Now I think to store only the text for link and tags and use linkify in frontend to render the href tags, but I'm looking a good solutions for the mentions. Maybe a serialized field with the mentions text and the id of the users?

I'm lookin for a solutions that help me with search post by content, and to retrieve a lot of content with fast query.

This is the draft-js json of two row with an hashtag and a mention (in entityMap)

{
  "blocks": [
    {
      "key": "19vrn",
      "text": "row 1 with mention and #hashtag",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [
        {
          "offset": 11,
          "length": 5,
          "key": 0
        }
      ],
      "data": {}
    },
    {
      "key": "46e6h",
      "text": "row 2",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [],
      "data": {}
    }
  ],
  "entityMap": {
    "0": {
      "type": "mention",
      "mutability": "SEGMENTED",
      "data": {
        "mention": {
          "name": "mention",
          "id": 53,
          "avatar": "b26be1f0-942b-11e9-bebb-a788574b8d0e.jpg",
          "title": ""
        }
      }
    }
  }
}

Solution

  • For those who are looking for the same problem, here is how I've solved this problem:

    I hope that this can help someone