Skip to content

Instantly share code, notes, and snippets.

View KitsonBroadhurst's full-sized avatar
:bowtie:
Building!

Kitson Broadhurst KitsonBroadhurst

:bowtie:
Building!
View GitHub Profile
import React, { useState, useEffect } from 'react'
// fetchOptionsGenerator is a bespoke header generator for our use case
import fetchOptionsGenerator from "./fetchOptionsGenerator"
/**
* Data fetching hook which takes a route url as a string
* and returns data from the backend for that route, along with a loading and error variable
* @param route: string
*/
@KitsonBroadhurst
KitsonBroadhurst / Item.jsx
Created February 12, 2020 18:05
Basic Material-UI component accessing our theme
import React from 'react'
import { Card,
CardActionArea,
CardMedia,
CardContent,
Typography,
CardActions,
Button } from '@material-ui/core'
import { makeStyles } from '@material-ui/styles'
import React, { useState, useLayoutEffect } from 'react'
const useWindowSize = () => {
const [size, setSize] = useState([0, 0])
useLayoutEffect(() => {
const updateSize = () => {
setSize([window.innerWidth, window.innerHeight])
}
@KitsonBroadhurst
KitsonBroadhurst / HooksFormValidation
Last active April 25, 2022 13:14
Form Validation with React Hooks - useState and useEffect
import React, { useState, useEffect, useRef } from 'react'
const SignUpForm = () => {
// we use the help of useRef to test if it's the first render
const firstRender = useRef(true)
// set a state variable which can be used to disable the save/submit button
// we set it to true so that the form is disabled on first render
const [disable, setDisabled] = useState(true)