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 Airtable, { Base } from 'airtable'; | |
import { DatabaseRecord } from "../../types/DatabaseRecord.interface"; | |
class AirTable { | |
private apiKey: string = import.meta.env.VITE_PWK; | |
private apiBase: string = import.meta.env.VITE_PWB; | |
public base: Base = this.getBase(this.apiKey, this.apiBase); | |
private dbRecords: DatabaseRecord[] = []; | |
private fetchNext!: () => void; |
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
// Higher-order component | |
const withSubscription = (WrapperComponent, selectData) => { | |
return (props) => { | |
const [data, setData] = useState([]); | |
useEffect(() => { | |
const handleChange = () => { | |
const newData = selectData(DataSource, props); | |
setData(newData); | |
} |
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 { useRef } from 'react'; | |
function App() { | |
const formInputRef = useRef(null) | |
const focusInput = () => { | |
formInputRef.current.focus(); | |
} | |
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 { useReducer } from 'react'; | |
const reducer = (state, action) => { | |
if(action.type === 'buy_ingredients') return {money: state.money - 10} | |
else if(action.type === 'sell_a_meal') return {money: state.money + 10} | |
return state; | |
} | |
function App() { | |
const initialState = {money: 100}; |
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"; | |
function App(){ | |
const [toggle, setToggle] = React.useEffect(false); | |
const handleToggle = () => { | |
setToggle(!toggle); | |
} | |
React.useEffect(() => { |
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
function App(){ | |
const [name, setName] = useState('') | |
const handleSubmit = (e) => { | |
e.preventDefault(); | |
setName('') | |
console.log('Form submitted successfully'); | |
} | |
const handleChange = (e) => { |
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 cat from './assets/images/cat.jpg'; | |
function showAnimal(){ | |
return ( | |
<div> | |
// Method 1 (name reference asset) | |
<img src={cat} alt="A picture of a cat" loading="lazy" title="A picture of a cat"/> | |
// Method 2 (path reference asset) | |
<img src={require('./assets/images/cat.jpg')} alt="A picture of a cat" loading="lazy" title="A picture of a cat"/> | |
</div> | |
// If you use method 2 then you don't have to use the import statement. |
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 {Routes, Route, Link} from 'react-router-dom' | |
import Homepage from './Homepage'; | |
import AboutMe from './AboutMe'; | |
function App() { | |
return( | |
<div> | |
<nav> | |
<Link to="/">Homepage</Link> | |
<Link to="/about-me">About Me</Link> |
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 {useMealsListContext} from '../providers/MealsProvider'; | |
const Counter = () => { | |
const {meals} = useMealsListContext(); | |
return ( | |
<div> | |
<h3>Number of meals today: {meals.length}</h3> | |
</div> | |
); | |
} |
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
<form class="form" method="post"> | |
<div class="form-group"> | |
<label for="booking-date">Booking date</label> | |
<input type="date" id="booking-date" name="booking-date" required> | |
</div> | |
<div class="form-group"> | |
<label for="booking-people">Number of people</label> | |
<input type="range" id="booking-people" name="booking-people" min="1" max="10" value="4" oninput="this.nextElementSibling.value = this.value" required> | |
</div> | |
<div class="form-group"> |
NewerOlder