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 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; | |
} | |
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, { AxiosError, AxiosResponse } from 'axios'; | |
import token from './somewhere'; | |
interface Todo { | |
id: string; | |
title: string; | |
} | |
interface User { | |
id: string; |
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 { 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 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 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 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 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 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 joe = { | |
update(message) { | |
console.log(`Joe receive ${message}`); | |
} | |
} | |
const jason = { | |
update(message) { | |
console.log(`Jayson read ${message}`); | |
} |
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 { useSelector } from './useSelector'; | |
const TodoList: React.FC = () => { | |
const { todos } = useSelector((state) => state.todos); | |
return ( | |
<ul> | |
{todos.map((todo) => ( | |
<li>{todo}</li> | |
))} |
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 { useSelector } from 'react-redux'; | |
const TodoList: React.FC = () => { | |
const { todos } = useSelector((state) => state.todos); | |
// Property 'todos' does not exist on type 'DefaultRootState'. | |
return ( | |
<ul> | |
{todos.map((todo) => ( | |
<li>{todo}</li> |
NewerOlder