This file contains hidden or 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
| https://tests.mettl.com/v2/authenticateKey/7cn1qxep6o | |
| https://tests.mettl.com/v2/authenticateKey/7corhx8ef4 |
This file contains hidden or 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
| <IfModule mod_rewrite.c> | |
| RewriteEngine On | |
| RewriteBase / | |
| RewriteRule ^index\.html$ - [L] | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteCond %{REQUEST_FILENAME} !-d | |
| RewriteCond %{REQUEST_FILENAME} !-l | |
| RewriteRule . /index.html [L] |
This file contains hidden or 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 runAsyncFunctions = async () => { | |
| const users = await getUsers() | |
| Promise.all( | |
| users.map(async (user) => { | |
| const userId = await getIdFromUser(user) | |
| console.log(userId) | |
| const capitalizedId = await capitalizeIds(userId) | |
| console.log(capitalizedId) |
This file contains hidden or 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 runAsyncFunctions = async () => { | |
| const users = await getUsers() | |
| for (let user of users) { | |
| const userId = await getIdFromUser(user) | |
| console.log(userId) | |
| const capitalizedId = await capitalizeIds(userId) | |
| console.log(capitalizedId) | |
| } |
This file contains hidden or 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
| // Third promise relies on the result of the second promise | |
| const capitalizeIds = (id) => { | |
| return new Promise((resolve, reject) => { | |
| return setTimeout(() => resolve(id.toUpperCase()), 200) | |
| }) | |
| } |
This file contains hidden or 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
| // Second promise relies on the result of first promise | |
| const getIdFromUser = (users) => { | |
| return new Promise((resolve, reject) => { | |
| return setTimeout(() => resolve(users.id), 500) | |
| }) | |
| } |
This file contains hidden or 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
| // First promise returns an array after a delay | |
| const getUsers = () => { | |
| return new Promise((resolve, reject) => { | |
| return setTimeout( | |
| () => resolve([{ id: 'jon' }, { id: 'andrey' }, { id: 'tania' }]), | |
| 600 | |
| ) | |
| }) | |
| } |
This file contains hidden or 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
| useEffect(() => { | |
| let cancelRequest = false; | |
| if (!url) return; | |
| const fetchData = async () => { | |
| dispatch({ type: 'FETCHING' }); | |
| if (cache.current[url]) { | |
| const data = cache.current[url]; | |
| dispatch({ type: 'FETCHED', payload: data }); | |
| } else { |
This file contains hidden or 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 initialState = { | |
| status: 'idle', | |
| error: null, | |
| data: [], | |
| }; | |
| const [state, dispatch] = useReducer((state, action) => { | |
| switch (action.type) { | |
| case 'FETCHING': | |
| return { ...initialState, status: 'fetching' }; |
This file contains hidden or 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 useFetch = (url) => { | |
| const cache = useRef({}); | |
| const [status, setStatus] = useState('idle'); | |
| const [data, setData] = useState([]); | |
| useEffect(() => { | |
| if (!url) return; | |
| const fetchData = async () => { | |
| setStatus('fetching'); | |
| if (cache.current[url]) { |
NewerOlder