The answer is received from chat-gpt and it comes in the console and sections of the browser itself, but when I put it in a div to write the answer, it doesn’t work, is there a problem?
class chat extends Component {
state = {
message: '',
displayChatBox: true,
inputText: '',
responseText: '',
header: { 'Content-Type': 'application/json; charset=UTF-8' }
};
handleChange = (e) => {
this.setState({ inputText: e.target.value });
};
fetchData = async () => {
const apiUrl = 'my url';
try {
const response = await axios.post(apiUrl, {
inputText: this.state.inputText
},
{
method: "POST",
headers: { 'Content-Type': 'multipart/form-data' }
}
);
this.setState({ responseText: response.data.response });
} catch (error) {
console.error('Error fetching data:', error);
}
};
handleSubmit = (event) => {
event.preventDefault();
this.fetchData();
};
sendMessage = () => {
const message = document.querySelector('.input').value;
this.setState({ message });
const tableElement = document.querySelector('.table');
tableElement.style.display = 'none';
}
How to display the answer in the page?
New contributor
Mahdi Rahimi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.