Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
How to connect highlight and comment functionality in React JS to backend (or local storage)

I am given the task to do the following:

  1. Select text (i am using selection API for that)
  2. Either add highlight or Comment to that text
  3. Send this highlighted or commented state to backend so that user can get his highlights on loading

I have completed the first two (and i am only doing the highlighting for now because commenting seems trivial after highlighting)

Now the data I am recieving as content is not simple data. It is coming from backend using a text editor I developed using SlateJS and I am manipulating that into arrays of HTML. So the data type I am receiving is different than normal HTML.

When I recieve the data, I am wrapping it with the component I built to implement highlighting and selection.

<TextSelectionComp sideEffectsOfHighlighting={sideEffectsOfHighlighting} isHighlightingActive={isHighlightingActive}>
    <TextEditorRenderOutput data={data} />
</TextSelectionComp>

Now I am confused on the third part on how to send (and then recover that data on load) Currently I am using local storage to develop this functionality and once that is done I shall tell the backend developer to build me an API for this.

This is the "data" object I am receiving inside TextEditorRenderOutput:

data: JSON.stringify({
    original: [
      {
        type: "paragraph",
        children: [
          {
            text: "No props given",
          },
        ],
      },
    ],
    htmlForm: ["<p>No props given</p>"],
  }),

This is the code I am using for my TextSelectionComp: https://codeshare.io/Qnb6Je

One way I am thinking is to build an array of objects. Each object can include window.getSelection object and the color. Again problem comes on how to use that to highlight the data on loady.

Second problem with that is I could not find a way to get the HTML elements of the "children" prop in my TextSelectionComp which I shared in codeshare link above.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!