-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref to textarea throwing exception. #80
Comments
I'm not sure what happened, but I'm sure there is no problem with https://codesandbox.io/s/react-textarea-code-editor-for-example-80-21gzg?file=/index.js Example:import React, { useEffect } from "react";
import ReactDOM from "react-dom";
import CodeEditor, { SelectionText } from "@uiw/react-textarea-code-editor";
function App() {
const textRef = React.useRef();
const [code, setCode] = React.useState(
`function add(a, b) {\n return a + b;\n}`
);
useEffect(() => {
if (textRef.current) {
const obj = new SelectionText(textRef.current);
console.log("obj:", obj);
}
}, []);
const onBold = () => {
console.log(">>", textRef.current);
// editorRef.current is pointing to some exception.
};
return (
<div>
<button onClick={onBold}>bold text</button>
<CodeEditor
value={code}
ref={textRef}
language="js"
placeholder="Please enter JS code."
onChange={(evn) => setCode(evn.target.value)}
padding={15}
style={{
backgroundColor: "#f5f5f5",
fontFamily:
"ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace",
fontSize: 12
}}
/>
</div>
);
}
ReactDOM.render(<App />, document.getElementById("container")); |
Sorry, I forgot to mention, issue is happening in nextjs project. |
https://codesandbox.io/s/react-textarea-code-editor-example-nextjs-gdzlw?from-embed Provide examples like above. |
@jaywcjlove |
I'm seeing a similar issue in my nextjs project. |
When trying to get ref to underlying textarea, it is returning some exception.
version: 1.4.15
sample code.
The text was updated successfully, but these errors were encountered: