Notes for Udemy Course “The Complete React Web Developer Course (with Redux)”

Notes for Udemy Course “The Complete React Web Developer Course (with Redux)” – https://www.udemy.com/react-2nd-edition/

React uses jsx and ES6 which means it requires Babel ( requires node ). Two scripts are required to work with React in the browser. React and ReactDOM. Below is a sample React component that has  toggle visibility functionality.

 

If components are nested, data as props can only be sent down – not up. So, on the parent component a method can be passed to the child component as a prop in order to send the information back to the parent.

Stateless functional components

Another type of component  that can be reduced to a single function call because they do not have any state to handle of their own. Mostly used for “presentation” type components. They can use props but aren’t accessible through *this* .

This type of component is “faster” as it has less overhead as it doesn’t handle state.

Small tricks for conditional rendering

For the arrow function, if you are return just an object you can use the following syntax:

In React, methods to update a parent component are passed down to child components via props.

Lifecycle methods

Methods are available to hook in to when a class based component is added/removed/updated in React. Common ones to use are componentDidMount() for fetching initial data, and componentDidUpdate(prevProps, prevState) for saving updated changes back to the db.

When using componentDidUpdate, make sure the prevState and current state are not equal ( !==) so that a save to db/localStorage is not called that is not needed.

 

Localstorage Notes

When within a method that was attached to a onClick event ( or any other similar method ), you can reference the field/value by the following type of example:

Children props ( slots )

Dynamic content that be added between a components tag can be added to be placed within the layout of the components it’s self. For example:

 

Simple form value/onChange practice:

Can create a single handleChange method to handle all form values and updates that are used in state.

Now we can use same method for all form fields:

 

Misc React Notes

In JSX, all normal html attributes such as onclick and onchange MUST be camel case.. i.e.e onClick and onChange

All components must start with a capital letter.

JSX conditional rendering :

ternary operator is accepted i.e. true ? ‘show this if true’ : ‘ value if false’

if/else can not be used in {} jsx since it is a statement and not an expression.

&& AND Operator

 

Notes for using Ajax in WordPress

While in WordPress admin area..  the variable named ajaxurl is available for javascript scripts to use for the url for ajax. Every call must at the very least have an “action” data property passed to WordPress in order for it to know which function will be used on the back-end to complete the ajax request.

The associated php that would be needed to process above :

Any ajax request must be handles by a function which has to be added via add_action

Note that any action you specify in the ‘action’ field for the data sent to the server will have ‘wp_ajax_’ prepended to the actions name.

Also need to bind to the action prefix ‘wp_ajax_nopriv’ so that the ajax will still work for visitors who are not logged in.

So the action ‘method_that_handles_the_ajax_request’ will have to be added in php as ‘wp_ajax_method_that_handles_the_ajax_request’ as seen in the php snippet.

If the action can not be found by admin-ajax.php the response returned from the ajax request will be an integer of zero ( 0 ).

If you created an ajax action method properly and you keep receiving a 0 response…confirm that your ajax action method was added.

Any function in php that handles a ajax request MUST end with die();

Within the php function, any post variable that is passed via the ajax data field, in our case the ‘address’ or ‘action’ field, is available via $_POST[“address”] or $_POST[“action”]


wp_localize_script

Used to add data to javascript that is normally only available on server side. Has to be used after an enqueue of a script and use the same “handle”. It will make the variables passed via localize_script available to the rest of the javascript that was enqueued.

Typically, this is used for nuances

Example of adding the nuances

Another way to add it when there are times where an additional script isn’t needed could be done in the following way.

 

 

 

Now we can update the javascript to use the nonce to pass back to WordPress to check for nonce validity.

Now that the nonce is created and is being passed from javascript to WordPress.. we setup below in php in the action that the ajax requests  to process it’s integrity.

 

Good notes for ajax usage: https://developer.wordpress.org/plugins/javascript/enqueuing/

 check_ajax_referer( 'nonce' );  This function will check nonce and if it fails will automatically kill the action it was ran within

 wp_send_json() will send back appropriate header and json back to javascript as well as wp_die() for the action it was called in.

Notes for “Advanced CSS and SASS” Udemy course

The course can be found at : https://www.udemy.com/advanced-css-and-sass

To center an absolute item in the middle of its  parent ( parent position must be set to relative ) with out using flex-box,the following can be done:

 

 

The following CSS3 property can be used to make an element not visible until its animation starts by having it’s 0% keyframe set  an opacity to 0. For example:

How CSS is processed and how styles that will be used will be determined:

!importance -> Specificity – > order that CSS is loaded ( cascade )

How relative values ( %, em, rem, vh , vw ) are converted to absolute values (px)

Relative values such as em and rem. em for fonts uses the parent element as it’s reference, em for lengths ( like padding etc ) uses the current element the  while rem uses the root element (html element) for both font and length type values.

Viewport-based : vh ( View Height) and vw (View Width) will use the devices View height/width to determine the site. So 90vh would be a height of 90% of the viewports height.

Misc Notes on Inheritance:

initial keyword resets a property to its initial value ( reset ).

Properties related to text ( font-family, size, color ) are inherited. Things like margin/padding are not by default. Can force inheritance of a property by using the inherit keyword on that property.

How and why to use rem instead of px

Set html element (root) font-size property to 10px  . This way when using rem in other element properties it is easier to figure out since it is a multiple/divisible by 10. This creates a good method in case the view point resizes. However, this is bad in the event that the user sets a different font size in their browser. Because of this, it is better to set the html element ( root ) to font-size of 62.5% . It is 62.5% because the default font-size in a browser is 16px. Since we want 10px, we use 10/16 = .625 or 62.5% for the font-size.

Box Types ( inline, block, inline-block )

All determined by the display: property.

 Block

Displayed as blocks. 100% of parent’s width. Vertically, one after another. Creates line breaks before and after it.

Inline

Inline box only occupies just the size it needs. Does not create line breaks. Height and width property do no apply. Can only apply left and right padding and margins.

Inline-block

Mostly inline that it only occupies content spaces that is using, does not create line breaks. Block on inside so all margin padding ( top and bottom) can be set.

Positioning Schemes

position: relative 

Elements laid out in natural order that is written in code. Not floats or absolutely positioned.

float: left  , float: right

Element is removed from the normal flow; Text and inline element will wrap around floated element. Container of a floated item will not adjust it’s height to the element but can use clear:both fixes

position: absolute; , position:fixed;

Element is removed from normal flow. No impact on surrounding contents/elements. Can use top,bottom, left and right to offset the element from its relatively positioned contained.

Stacking contexts

z-index

higher z-index appears on top, the lower the z-index the lower on the stack.

SASS

Variables

Can be used to store any type of values, must start with $ – for example:

$text-color:#f2f2f2;

$button-width:150px;

Nesting

Can nest elements/classes to reduce the need to rewrite certain code. For example:

is used to join the pseudo element or state to the element before it. With out  it, it would of produced .nav :hover {} instead which is not what was intended.

darken and lighten

Color methods in SASS to darken/lighten a color. First param is the color. Second param is the % you want to adjust it by. i.e.

darken(#f2f2f2,15%); or lighten(#f2f2f2,10%);

Mixin

A type function or block of code you can define to use in different areas of your css.

To define a mixin:

Can also use parameters i.e.

Misc Notes

In order to use scss variables in the calc() function it must be enclosed within #{ }

To make text or a font type icon have a gradient  background you can do the following CSS:

To use a linear-gradient, you must apply it to the background-image property.

box-decoration-break or -webkit-box-decoration-break

If a single line of text i.e. <p> line of text that exceeds more than 1 line</p> exceeds a single line.. any padding added to the element would normally not apply to both lines if the element is broken in to two lines. Can use box-decoration-break:clone; to make it so any padding added to the element will be applied to both ( or more ) lines for that element.

Notes if rotating an object

perspective & -moz-perspective:   

Add a decent amount of pixels to smooth the rotation to look more natural. Must be added to the parent element.

backface-visibility:hidden;

Will make the backside of an element not visible . i.e. if it is transform: rotateY(180deg);

 

 

Python script to scrape array of urls and create an excel spreadsheet

I created this in order to have a bootstrap for wanting to create a script to generate an excel spreadsheet from scraped information from an array of urls. Comments within the script indicate which values/columns/headers need to be updated.

 

 

Example of C# delegate/event to pass data from one form to another