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 api = { | |
posts: "https://jsonplaceholder.typicode.com/posts" | |
}; | |
export async function request<T>(url: string): Promise<T> { | |
const response = await fetch(url); | |
const body = await response.json(); | |
return body; | |
} |
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
// action types | |
enum CounterActionTypes { | |
increment = 'increment', | |
decrement = 'decrement' | |
} | |
// interfaces & types | |
interface CounterState { | |
value: number | |
} |
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, { useState } from "react"; | |
interface IProps { | |
onClick: (event: React.SyntheticEvent) => void; | |
text: string; | |
} | |
const Button: React.FC<IProps> = ({ onClick, text }) => { | |
const [clickCount, setCount] = useState(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
import React, { useState } from "react"; | |
const Button = ({ onClick, text }) => { | |
const [clickCount, setCount] = useState(0); | |
const handleClick = (event) => { | |
setCount(clickCount + 1); | |
onClick(event); | |
}; |
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
class Counter = { | |
constructor(initial) { | |
this.value = initial | |
} | |
increment() { | |
this.value += 1 | |
} | |
decrement() { |
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 config = { | |
API_URL: process.env.REACT_APP_API_BASE_URL, | |
} | |
axios.get(config.API_URL) |
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 { setApiHeader, api } from '../config' | |
async function authenticate() { | |
// Authorization | |
const response = await api.post('/auth') | |
// Getting token from response | |
const { token } = response | |
// Set header for the next authenticated requests |
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 { useState } from 'react' | |
import { useList, useToggle } from 'react-use' | |
import fetchImages from './fetchImages' | |
const useFetchImages = ({ source }) => { | |
const [images, imagesActions] = useList([]) | |
const [isLoading, toggleLoading] = useToggle(false) | |
const [error, setError] = useState(null) | |
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 { saveState, loadState } from '../utils/localStorage' | |
const save = data => saveState(data, 'key') | |
const load = () => loadState('key') |
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 from 'react' | |
import PropTypes from 'prop-types' | |
import TodoItem from '../TodoItem' | |
// prop-types | |
const propTypes = { | |
todos: PropTypes.arrayOf(PropTypes.object), | |
} |
NewerOlder