question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG]: Does not work with outside variables

See original GitHub issue

Describe 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

  1. with <ControlledEditor> [BUG] image
  2. with <textarea> [Expected output] image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: 84

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
urishcommented, Aug 21, 2020

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! 🙏

1reaction
suren-atoyancommented, Aug 21, 2020

Okay, let me think about it, I will inform you here or send you an email if I find a solution for that.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found