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
<html> | |
<head> | |
<title>JS Sandbox</title> | |
</head> | |
<body> | |
<script> | |
const object = { | |
test: "test", | |
paul: "paul", | |
morning: { test: "test", paul: "paul" } |
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 React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
class Legacy extends Component { | |
render() { | |
const { name } = this.props; | |
const { api } = this.context; | |
return ( | |
<div> | |
<h1>Hello, {name}</h1> |
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 React, { Component, createContext } from 'react'; | |
import PropTypes from 'prop-types'; | |
const ExampleContext = createContext({ api: 'lorem ipsum' }); | |
class New extends Component { | |
static contextType = ExampleContext; | |
render() { | |
const { name } = this.props; |
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 React, { Component, createContext } from 'react'; | |
import PropTypes from 'prop-types'; | |
const ExampleContext = createContext({ api: 'lorem ipsum' }); | |
/* | |
* This is an example when we can't access this.context as the Context component | |
* has been upgraded to use the new API while the Legacy component is relying on the old one. | |
*/ | |
class Legacy extends Component { |
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 React, { Component, createContext } from 'react'; | |
import PropTypes from 'prop-types'; | |
const ExampleContext = createContext({ api: 'lorem ipsum' }); | |
class New extends Component { | |
static contextType = ExampleContext; | |
render() { | |
const { name } = this.props; | |
const { api } = this.context; |
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
<html> | |
<head> | |
<style> | |
body style { | |
display: block; | |
} | |
</style> | |
</head> | |
<body> | |
<style contenteditable> |
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 axios from 'axios'; | |
import { LANGUAGE_NAME, REFRESH_TOKEN_IN_STORE, TOKEN_NAME_IN_STORE } from '../constants/api'; | |
import { getBrowserLang, setTokens } from './GlobalHelper'; | |
import { logoutDispatch } from './StoreHelper'; | |
import LocalStorageHelper from './LocalStorageHelper'; | |
import { BACKEND_ROUTES } from '../constants/routes'; | |
export const API_REQUEST_AUTH_USER_LOGIN_URL = '/users/login'; | |
export const API_REQUEST_AUTH_USER_LOGIN_SOCIAL_URL = '/login/social'; |
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
// what will be the output to the console? | |
console.log(1); | |
setTimeout(() => { | |
console.log(2); | |
setTimeout(() => console.log(3), 200); | |
}, 200); | |
new Promise(() => console.log(4)); |
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
var length = 10; | |
function fn() { | |
console.log(this.length); | |
} | |
var obj = { | |
length: 5, | |
method: function (fn) { | |
fn(); | |
arguments[0](); | |
}, |
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
/* | |
PROMISE/THEN approach | |
*/ | |
const userIds = [1, 2, 3]; | |
const requests = userIds.map((userId) => | |
fetch(`https://jsonplaceholder.typicode.com/users/${userId}`), | |
); | |
Promise.all(requests) |
OlderNewer