constructor(props) {
super(props);
this.state = {
index: 0,
timethen: new Date(),
wordIndex: 0,
sentenceArray: sentence.split(" "),
wpm: 0,
typedWords: "",
};
this.socket = io("http://localhost:3000");
this.handleChange = this.handleChange.bind(this);
this.createFullSentence = this.createFullSentence.bind(this);
}
componentDidMount() {
var name = prompt("Plese enter your name");
this.socket.emit("init", name);
}
componentDidUpdate() {
console.log(" I am here ");
this.socket.emit("update", this.state.wordIndex);
}
In this the console.log() statement is being executed but the this.socket.emit(“update”,this.stae.wordIndex); statement is not being executed at all!
this is my client side code.
io.on("connection", (socket) => {
console.log("user connected", socket.id);
socket.on("init", (name) => {
socket.broadcast.emit("new-user", name);
console.log(name);
});
socket.on("update", (index) => {
console.log("You are in index", index);
});
socket.on("disconnect", () => {
console.log(socket.id, "disconnected");
});
});