[BUG]: Does not work with outside variables
See original GitHub issueDescribe the bug
The value of variables is locked in the function passed to the onClick
handler of <ControlledEditor>
.
Check the code snippet and screenshots to repro the bug.
To Reproduce
Type in the editor and check console to reproduce the bug: Run it here: https://codesandbox.io/s/hopeful-dubinsky-kdl3j
import React, { useState } from "react";
import { ControlledEditor } from "@monaco-editor/react";
import './App.css';
export function B({onChange}) {
return <ControlledEditor onChange={onChange}/>;
}
export function A() {
const [state, setState] = useState('');
function handleChange(e, v) {
// [BUG]: Initial value of state is logged every time, despite it value being updated via setState
console.log(v, ',', state);
setState(v);
}
return (
<div className="editor">
<B onChange={handleChange}/>
</div>
);
}
It works as expected when used with the inbuilt <textarea/>
component.
Expected behavior
Updated value of state
should get logged, but actually initial value is logged every time.
Please check the screenshot for current and expected behavior.
Screenshots
- with
<ControlledEditor>
[BUG] - with
<textarea>
[Expected output]
Desktop (please complete the following information):
- OS: Windows 10
- Browser: Chrome
- Version: 84
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why can't I add value to outside variables inside a function?
I am a beginner python coder trying to develop a simple text adventure game for a project. Most of the bugs and issues...
Read more >Variable Scope | Fix error: 'yourVariable' was not declared in ...
If I create my own function and create a variable inside that function it can't be used outside of that function. Let me...
Read more >5142.857142857143]:Cannot access outer variable inside a ...
Nikhil-Nandagopal changed the title [Bug]: SetInterval inside JS function does not have access to the variable declared in the same scope.
Read more >Bug with global variable - Power Platform Community - Microsoft
Hi everyone, I just posted this bug report in Sudden err but no dev changes made 'Types of the specified context variables are...
Read more >Debugger doesn't show variables *outside* lambda
This is happening even if said variables are marked final, and regardless of whether they're being accessed inside the lambda. The error message...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can confirm the new version fixes the issue for me. Now I can finally use monaco in the Arduino Library samples page.
Thank you! 🙏
Okay, let me think about it, I will inform you here or send you an email if I find a solution for that.