Using document.querySelector in React? Should I use refs instead? How?

I can’t answer the “should you” part of whether to use refs for this instead other than if you do, you don’t need those id values unless you use them for something else. But here’s how you would: Use useRef(null) to create the ref. const activeSlideRef = useRef(null); Put it on the Slide that’s currently … Read more

How to properly reference local resources in HTML?

A leading slash tells the browser to start at the root directory. If you don’t have the leading slash, you’re referencing from the current directory. If you add two dots before the leading slash, it means you’re referencing the parent of the current directory. Take the following folder structure notice: the ROOT checkmark is green, … Read more

Assigning out/ref parameters in Moq

For ‘out’, the following seems to work for me. public interface IService { void DoSomething(out string a); } [TestMethod] public void Test() { var service = new Mock<IService>(); var expectedValue = “value”; service.Setup(s => s.DoSomething(out expectedValue)); string actualValue; service.Object.DoSomething(out actualValue); Assert.AreEqual(expectedValue, actualValue); } I’m guessing that Moq looks at the value of ‘expectedValue’ when you … Read more

When to use ref and when it is not necessary in C#

Short answer: read my article on argument passing. Long answer: when a reference type parameter is passed by value, only the reference is passed, not a copy of the object. This is like passing a pointer (by value) in C or C++. Changes to the value of the parameter itself won’t be seen by the … Read more