fix plugin state initialization

Summary: Many plugins initialized their state in the init function. Due to changes in how plugins are rendered, the init-function might be called after the initial render and therefore the state being undefined at the first render. This moves the state initialization into a instance variable to ensure they are created before the first render.

Reviewed By: jknoxville

Differential Revision: D8746242

fbshipit-source-id: 04af039da2dc00c14a2d8ac42b72559ce789ef57
This commit is contained in:
Daniel Büchele
2018-07-06 03:16:35 -07:00
committed by Facebook Github Bot
parent d8cf48d750
commit 809136fc29

View File

@@ -51,6 +51,11 @@ export default class extends SonarPlugin<SharedPreferencesState> {
static title = 'Shared Preferences Viewer';
static id = 'Preferences';
state = {
changesList: [],
sharedPreferences: null,
};
reducers = {
UpdateSharedPreferences(state: SharedPreferencesState, results: Object) {
return {
@@ -94,14 +99,6 @@ export default class extends SonarPlugin<SharedPreferencesState> {
);
}
constructor() {
super();
this.state = {
changesList: [],
sharedPreferences: null,
};
}
onSharedPreferencesChanged = (path: Array<string>, value: any) => {
const values = this.state.sharedPreferences;