Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Fix issue where render may be called due to unnecessary state change
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Jan 23, 2019
1 parent a7a9fc7 commit dd26cfe
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/screens/Compose.js
Expand Up @@ -50,7 +50,9 @@ export default class Compose extends Abstract {
if(noteId) { note = ModelManager.get().findItem(noteId);}
this.setNote(note, true);

this.constructState({title: this.note.title, noteLocked: this.note.locked /* required to re-render on change */});
// Use true/false for note.locked as we don't want values of null or undefined, which may cause
// unnecessary renders.
this.constructState({title: this.note.title, noteLocked: this.note.locked ? true : false /* required to re-render on change */});

this.configureHeaderBar();

Expand Down Expand Up @@ -91,7 +93,10 @@ export default class Compose extends Abstract {
Do not make text part of the state, otherwise that would cause a re-render on every keystroke.
*/
this.setState({title: this.note.title, noteLocked: this.note.locked});

// Use true/false for note.locked as we don't want values of null or undefined, which may cause
// unnecessary renders. (on constructor it was undefined, and here, it was null, causing a re-render to occur on android, causing textview to reset cursor)
this.setState({title: this.note.title, noteLocked: this.note.locked ? true : false});
}
}
});
Expand Down

0 comments on commit dd26cfe

Please sign in to comment.