I am using Google Speech-To-Text API for answering questions of my web page using user's speech. In this case I have created all of the Node JS server side functions correctly, when I start API then server sends the text of speech constantly to client using webSockets. My issue is on the React JS client.js file. When received the text of speech to client from server, the useEffect is not refresh the #text-field(input tag) of web browser.
client.js file
import io from 'socket.io-client';
import React from 'react';
import ReactDOM from 'react-dom';
import { useEffect, useState } from 'react';
const socket = io('http://localhost:3000', {
transports: ['websocket', 'polling']
});
const App = ({}) => {
const [data, setData] = useState([]);
useEffect(() => {
socket.on('speech', textOfSpeech => {
setData(currentData => [...currentData, textOfSpeech ]);
});
}, []);
return (
<div>
<h1>Message</h1>
<input id="text-field" type="text" value={data.join('')}/>
</div>
);
};
ReactDOM.render(<App />, document.getElementById('root')); ```
When I refresh the web page, then all text of speech display in the #text-field, without refreshing the web page I can not get the text of speech. Please help me to update the #text-field without refreshing the web page.