#javascript #reactjs
Вопрос:
То, что я пытаюсь сделать, — это иметь несколько кнопок для создания разных элементов. Заголовок-это сообщение об ошибке, которое появляется в моей консоли при запуске приложения.
Это моя ссылка codesandbox, которая показывает код и ошибку. Нажмите на ссылку и откройте консоль, там ошибка
функция создания диаграммы
onChartItem() {
/*eslint no-console: 0*/
console.log("adding", "n" this.state.newCounter);
this.setState({
// Add a new item. It must have a unique key!
charts: this.state.charts.concat({
i: "n" this.state.newCounter,
x: (this.state.charts.length * 2) % (this.state.cols || 12),
y: Infinity, // puts it at the bottom
w: 8,
h: 6
}),
// Increment the counter to ensure key is always unique.
newCounter: this.state.newCounter 1
});
}
любые советы будут оценены по достоинству
Ответ №1:
Я меняюсь this.onChartItem = this.onChartItem(this);
на это this.onChartItem = this.onChartItem.bind(this);