Copying a state variable’s value
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
3M ago
To copy the value of a variable declared using useState, if it’s an array use: let varName = [...stateVar]; If it’s not an array use: let varName = stateVar.valueOf ..read more
Visit website
Creating an array of empty arrays
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
3M ago
If you do: let arr = new Array(5); arr.fill([]); This will make an array of 5 identical arrays where editing one will update all which is rarely what anyone wants. To achieve an array of different arrays use: let arr = Array.from(new Array(5), () => ..read more
Visit website
Update all dependencies in package.json to latest
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
6M ago
To do this, use npm-check-updates Install with Then update with ..read more
Visit website
Accessible hash links
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
6M ago
This is mainly for the ‘skip to content’ links. $("a[href^='#']").not("a[href]='#'").click(function() {    $("#"+$(this).attr("href").slice(1)+"").focus ..read more
Visit website
Difference between var, let and const
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
6M ago
var declarations are globally scoped or function scoped while let and const are block scoped. This means you can declare the a let or const with the same name inside an if statement and it will be self contained. The console would log “aa bb” followed by “a b”. Let and const can’t be redeclared in ..read more
Visit website
Difference between document.ready and window.onload
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
6M ago
Triggers when the HTML is ready. Use this to start running code as soon as possible. This is not jQuery. Trigger when everything on the page (eg images) is finished loading ..read more
Visit website
CSS Modules
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
6M ago
CSS modules allow you to create unique class names even when the class is already used in another file. Name the file like so: name.module.css. Right normal css in it. Import the file like so: Apply it to an element like so: where testClass is a class specified in your css module file. When the ..read more
Visit website
Passing a function prop from child to parent
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
6M ago
Using the same example as passing a function from parent to child but going in the opposite direction. Here the parent has a callback function and passes it to the child component. The child calls the callback with it’s own function as the argument. As before you can use the component like so ..read more
Visit website
Passing a function prop from parent to child
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
6M ago
We have a Parent component that contains the child component “ChildBtn”. Parent has the function parentFunction which is passed into the child. We can also specify the console log text and the button text. We can then use the component like so ..read more
Visit website
JQuery scrolling logic
Projectmw Blog | Weekly Indie Game Dev Updates.
by Mark
6M ago
..read more
Visit website

Follow Projectmw Blog | Weekly Indie Game Dev Updates. on FeedSpot

Continue with Google
Continue with Apple
OR