This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const changeUsersName = (name) => { | |
return { | |
type: "CHANGEUSERNAME", | |
payload: name, | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inititalState = { name: "User 1", age: 23 }; | |
const addUserReducer = (state = inititalState, action) => { | |
switch (action.type) { | |
case "CHANGEUSERNAME": { | |
return { ...state, name: action.payload }; | |
} | |
case "CHANGEAGE": { | |
return { ...state, age: action.payload }; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inititalState = { name: "User 1", age: 23 }; | |
const userReducer = (state = inititalState, action) => { | |
switch (action.type) { | |
case "CHANGEUSERNAME": { | |
return { ...state, name: action.payload }; | |
} | |
} | |
return state; | |
}; | |
export default userReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hello from './hello.js' | |
console.log(hello()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default () => { | |
return "Hello World!" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const h1 = document.getQuerySelector('h1).innerHTML = "New text for the H1 element" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myPromises = urls.map((url) => fetch(url).then((res) => res.json())); | |
Promise.all(myPromises).then((data) => { | |
// When all requests have finished | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(() => { | |
console.log("Using callback queue") | |
}, 0) | |
new Promise(resolve => resolve(console.log("Using micro queue"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const user = new XMLHttpRequest(); | |
user.open("GET", "/user"); | |
user.send(); | |
user.onload = () => { | |
const getPosts = new XMLHttpRequest(); | |
getPosts.open("GET", `/posts${user.response.id}`); | |
getPosts.send(); | |
getPosts.onload = () => { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reqListener () { | |
alert(this.responseText) | |
} | |
var oReq = new XMLHttpRequest(); | |
oReq.addEventListener("load", reqListener); | |
oReq.open("GET", "https://jsonplaceholder.typicode.com/todos/1"); | |
oReq.send(); |