javascript - 我来自后端的套接字连接在反应应用程序的渲染内容中产生问题
问题描述
当我尝试制作实时文本编辑器时,我的套接字连接来自节点服务器,我正在使用JoditEditor
富文本编辑器,因为问题是每当我尝试在编辑器中输入多个单词时,我的光标都会重置,我必须如果我可以连续在编辑器上书写,请再次单击编辑器以根据需要写下一个单词
import React, { useState, useRef, useEffect } from "react";
import JoditEditor from "jodit-react";
import { socket } from "../socketConfig";
function Msg(props) {
const editor = useRef(null);
const [message, setmessage] = useState(props.message);
const [roomid, setroomid] = useState(props.roomid);
const [sid, setsid] = useState([]);
const configEditor = { readonly: false };
const handleChange = (data) => {
//sending message to above room
socket.send(data, "ankit", roomid);
socket.on("message", (data) => {
console.log(data);
setmessage(data);
});
};
useEffect(() => {
//geting socket id for new user
socket.on("newuser", (data) => {
setsid(data);
console.log("UC");
});
}, [message, roomid]);
return (
<>
<h5>{message}</h5>
<JoditEditor
ref={editor}
value={message}
config={configEditor}
tabIndex={1}
onChange={handleChange}
/>
</>
);
}
export { Msg };
解决方案
推荐阅读
- react-native - 如何在wix Navigation中将道具传回父组件
- php - Laravel msql配置%db_name%缓存问题
- mql4 - 如何分离 2 Close[1]?
- python - 对隐式列名的操作
- file-manager - DotNetNuke 中的文件管理器模块
- typescript - 如何在 ag-grid 中禁用箭头键、主页键和结束键作为导航?
- vue.js - 用于多个异步上传的 axios 所有进度条
- android - 如何注入这样的网络模块?
- angularjs - 如何在 angularJS 中显示 HTML 内容值
- javascript - Adobe Photoshop Extension 打开另存为对话框