Подсказка вопроса: < /p>
В компоненте TableView, который вы визуализировали ранее, рендеринг всех
Comments /Data, вытянутые из Backend #hint: Create Columns Array и
Complys atest Adviewer vouder inder indo indo inder < /p>
< /black> Часть столбца в файле mycomponet.js или в моем предварительном файле TableViewer.js. < /p>
Я попробовал создать приведенный ниже код из моего компонента.import React, { Component } from 'react';
import TableViewer from '../utilities/TableViewer';
class MyComponent extends Component {
state = {
message: '',
response: '',
tableData: [],
columns: [
{ title: 'ID', field: 'id' },
{ title: 'Comment', field: 'text' }
]
};
handleChange = (event) => {
this.setState({ message: event.target.value });
};
handleSubmit = async () => {
const { message } = this.state;
const response = await fetch('/api/message', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message }),
});
const data = await response.json();
this.setState({ response: data.message });
};
getMessage = async () => {
try {
const response = await fetch('/comments'); // Fetch comments from the backend
const data = await response.json();
this.setState({ tableData: data }); // Store the fetched comments in state
} catch (error) {
console.error('Error fetching comments:', error);
}
}
componentDidMount() {
this.getMessage(); // Fetch comments when the component mounts
}
render() {
const { message, response, tableData, columns } = this.state;
return (
Threat Portal Mockup
Submit
Response: {response}
{/* New section for TableViewer */}
Table Viewer Section
);
}
}
export default MyComponent;
Подробнее здесь: https://stackoverflow.com/questions/796 ... -the-below