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
[Bug] Cursor will move to the beginning when using prop "value" #199
Comments
Temporary solution for this: use export function CodeMirror({ value, onChange, ...rest }: ReactCodeMirrorProps) {
let [initVal, setInitVal] = useState(value)
let valRef = useRef(value)
useEffect(() => {
if (valRef.current !== value) {
setInitVal(value)
}
}, [value])
return (
<CodeMirror
onChange={(val, viewUpdate) => {
valRef.current = val
onChange && onChange(val, viewUpdate)
}}
value={initVal}
{...rest}
/>
)
} |
It seems that I have fixed this feature. |
Thanks for your quick response! @jaywcjlove I'll bump my version. |
I feel like I'm running into this same issue. What I'm doing:
The Video |
In example, the value is assigned as a constant. However if the value is read from a state, like minor tweak of the example below:
Here's the bug in v4:
useCodeMirror
hookCodeSandbox:
https://codesandbox.io/s/react-codemirror-example-codemirror-6-forked-d9u0g?file=/src/App.js
The text was updated successfully, but these errors were encountered: