Web resources
Web resources
Colour Theory:
Typography: exx - Stangith for the titles And Sofia pro for body text.
User Interface Design:
Example using Promise
let myPromise = new Promise(function(myResolve, myReject) {
let req = new XMLHttpRequest();
req.open('GET', "mycar.htm");
req.onload = function() {
if (req.status == 200) {
myResolve(req.response);
} else {
myReject("File not Found");
}
};
req.send();
});
myPromise.then(
function(value) {myDisplayer(value);},
function(error) {myDisplayer(error);}
);
Example
function myDisplayer(some) {
document.getElementById("demo").innerHTML = some;
}
if (x == 0) {
myResolve("OK");
} else {
myReject("Error");
}
});
myPromise.then(
function(value) {myDisplayer(value);},
function(error) {myDisplayer(error);}
);
Using Promise response and reject for waiting for response of API call:
Using Async and await to wait until we get data then console log the data.
There are two types of exports: Named Exports and Default Exports.
Named Exports
Let us create a file named person.js, and fill it with the things we want to
export.
You can create named exports two ways. In-line individually, or all at once at
the bottom.
In-line individually:
person.js
Default Exports
Let us create another file, named message.js, and use it for demonstrating
default export.
Example
message.js
Import
You can import modules into a file in two ways, based on if they are named
exports or default exports.
Named exports are constructed using curly braces. Default exports are not.
JavaScript Callbacks
A callback is a function passed as an argument to another function.
Using a callback, you could call the calculator function ( myCalculator) with
a callback (myCallback), and let the calculator function run the callback after
the calculation is finished:
Example
function myDisplayer(some) {
document.getElementById("demo").innerHTML = some;
}
myCalculator(5, 5, myDisplayer);
return (
<div className="App">
<button onClick={() => {setCount(count + 1)}}>Increase</button>
<button onClick={() => {setCount(count - 1)}}>Decrease</button>
<button onClick={() => {setCount(0)}}>Set to Zero</button>
{count}
</div>
);
Here count is an example of state.
Custom Hooks:
Use Object {} : When we want to have predefined variables name then return
state in form of Object.
Use Array [] : When we do not want variable name to be predefined and we
can change variables name then we should return state in the array.
Types of Hook: 1) UseState:
To start a new Create React App project with TypeScript, you can
run:
Next.js:
Features which are different from the react:
1) Enhance SEO – by using the concept of server-side rendering we can load
the html and css at server side then browser can open the web page without
processing the html and css at client side which improves SEO(ranking or
website).
2) Routing – In react we use additional package known as react-router-dom for
routing purpose but the next.js uses file-based routing system which help us
simplifying routing.
3) Ability to create full Stack web application – next.js has a new feature known
as API routes enabling the creation of serverless functions to handle the API
requests. Serverless APIs in Next.js is a way of creating API endpoints without
any need for a traditional server. For creating an API endpoint for a particular
route just create a file route.js for a particular folder.