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 subject = { | |
observers: [], | |
subscribe(observer) { | |
this.observers.push(observer) | |
}, | |
notify(message) { | |
this.observers.forEach(observer => observer.update(message)); | |
} | |
} |
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 subject = { | |
observers: [], | |
subscribe(fn) { | |
this.observers.push(fn) | |
}, | |
notify(arg) { | |
this.observers.forEach(fn => fn(arg)); | |
} | |
} |
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
import axios from 'axios'; | |
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; | |
const api = { | |
getData: () => axios.get('/todos/1') | |
}; | |
export default api; |
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
import axios from 'axios'; | |
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; | |
axios.interceptors.response.use(res => res.data | |
, error => { | |
const { data, status, config } = error.response; | |
switch(status) { | |
case 400: | |
console.error(data); |
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
import axios from 'axios'; | |
import { token } from './somewhere'; | |
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; | |
axios.interceptors.request.use((config) => { | |
if (token) { | |
config.headers.Authorization = `Bearer ${token}`; | |
} | |
return config; |
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
import axios, { AxiosError, AxiosResponse } from 'axios'; | |
import token from './somewhere'; | |
interface Todo { | |
id: string; | |
title: string; | |
} | |
interface User { | |
id: string; |
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 DropDownList = () => { | |
const [focus, setFocus] = useState(false); | |
const ref = useRef(null); | |
useEffect(() => { | |
const listener = (event) => { | |
if ( ref.current && event.target && ref.current.contains(event.target)) { | |
return; | |
} | |
OlderNewer