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

319
Views
Draft.JS: the proper way to detect content change

There is onChange event, but it fires also when carret moves or navigation (arrows etc) button being pushed.

I want to detect if content was changed. Basically i need to detect this only once when the very first change occur. The dumb way "compare content" may work here, but this is an anti-pattern because this task is too resources-expensive.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Since Draft uses an immutable data structure, it doesn't have to be that resource heavy – comparing references should be enough:

onChange(newEditorState) {
  const currentContent = this.state.editorState.getCurrentContent()
  const newContent = newEditorState.getCurrentContent()

  if (currentContent !== newContent) {
    // Content has changed
  }
}
over 4 years ago · Santiago Trujillo Report
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!