Quantcast
Channel: Projectmw Blog
Browsing all 75 articles
Browse latest View live

Using Reduce

Reduce is used somewhat similar to ‘map’ Zero is set as the initial value and then it goes through the array and adds each value (in this example the currentScore) to the totalScore which becomes the...

View Article


Full size background image

Background-size cover makes the image cover the whole screenBackground-position center centers the imageBackground-attachement fixed makes it so the image doesn’t move when you scroll down the page.

View Article


Basic unit testing with Jest

Let’s say for example we have a back end function that checks if you are under age from a user’s date of birth. First we load that function: Then we set up some test data, like so: We then run the...

View Article

Looping through js objects with “for in”

To “map” through a js object use “for in” First we get each item in the object and call it ‘person’ to make it easier to read. Then loop through it’s data to populate the array. In our example “data”...

View Article

Removing env file from file

After adding .env to the .gitignore file, use to remove it from git. To remove it completely from the history use

View Article


Good email regex

This is just one I found and seems pretty good

View Article

Open new chrome browser with no security

Put this in the terminal: This will bypass some things like cors errors and can be useful for development.

View Article

React: Cloning elements with React.cloneElement()

Use this to copy elements and give them different props or add new ones. We have a Button which accepts the props textColor and backgroundColor. Then we have ButtonContainer which clones it’s children...

View Article


Alternative to running useEffect once

This is an alternative to running useEffect without any parameters.

View Article


Animate objects depending on scroll position

For any items on the page that you want to animate when scrolled to add a ‘data-scroll-class’ attribute with the string of what class you want to add to animate and an optional ‘data-scroll-delay’...

View Article

CSS gradient mask

This is the CSS on the containing div. Play around with the settings for different effects. Demo here

View Article

JQuery scrolling logic

View Article

Passing a function prop from parent to child

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

View Article


Passing a function prop from child to parent

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

View Article

CSS Modules

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

View Article


Difference between document.ready and window.onload

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.

View Article

Difference between var, let and const

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

View Article


Accessible hash links

This is mainly for the ‘skip to content’ links. $("a[href^='#']").not("a[href]='#'").click(function() {    $("#"+$(this).attr("href").slice(1)+"").focus(); });

View Article

Animate objects depending on scroll position

For any items on the page that you want to animate when scrolled to add a ‘data-scroll-class’ attribute with the string of what class you want to add to animate and an optional ‘data-scroll-delay’...

View Article

CSS gradient mask

This is the CSS on the containing div. Play around with the settings for different effects. Demo here

View Article
Browsing all 75 articles
Browse latest View live