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, useEffect } from "react"; | |
import { getUsers } from "./services/userService"; | |
export default function CentralDemo() { | |
const [users, setUsers] = useState([]); | |
const [loading, setLoading] = useState(true); | |
const [error, setError] = useState(null); | |
useEffect(() => { | |
getUsers() | |
.then(json => { |
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 function getUsers() { | |
return fetch(`${process.env.REACT_APP_API_BASE_URL}users`).then(response => | |
response.json() | |
); | |
} |
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, useEffect } from "react"; | |
export default function InlineDemo() { | |
const [users, setUsers] = useState([]); | |
const [loading, setLoading] = useState(true); | |
const [error, setError] = useState(null); | |
useEffect(() => { | |
fetch(`${process.env.REACT_APP_API_BASE_URL}users`) | |
.then(response => { |
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, useEffect } from "react"; | |
/* Track whether user is interacting via keyboard. | |
This is used to determine if we should show focus rings. | |
Focus rings should only display on focus when isTabbing is true. | |
*/ | |
export default function useIsTabbing() { | |
const [isTabbing, setIsTabbing] = useState(false); | |
useEffect(function listenForMouseClicksAndKeydowns() { |
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, { Suspense } from "react"; | |
import "./InlineAlert.scss"; | |
import cx from "classnames"; | |
import * as ReactIs from "react-is"; | |
const allowedChildren = ["string", "span", "em", "b", "i", "strong"]; | |
type InlineAlertProps = { | |
/** Message to display */ | |
children: React.ReactNode; |
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, { useEffect } from "react"; | |
import PropTypes from "prop-types"; | |
import { Prompt } from "react-router-dom"; | |
// Prompt the user onbeforeunload or when navigating away by clicking a link | |
export default function PromptOnUnload({ when, message }) { | |
const enabled = when; | |
useEffect(() => { | |
if (!enabled) return; | |
const handleBeforeUnload = (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
/** | |
This provides bank holidays and a function to request bank holidays. | |
This is currently only used by the datepicker. | |
This provider assures each year's bank holidays are only requested once for a given app. | |
Place this provider at the app's entry point so that all child components can consume it. | |
**/ | |
import React, { useState, useRef } from "react"; | |
import PropTypes from "prop-types"; | |
import BankHolidaysContext from "./BankHolidaysContext"; | |
import { convertToDateObjects } from "../../../utils/dateUtils"; |
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, { | |
isValidElement, | |
Suspense, | |
useState, | |
useRef, | |
useEffect | |
} from "react"; | |
import PropTypes from "prop-types"; | |
import { Route } from "react-router-dom"; | |
import H1 from "reusable/lib/H1"; |
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
// Hook to make consuming Alert context more convenient | |
import { useContext } from "react"; | |
import AlertContext from "../components/AlertContext"; | |
import { ALERT_TYPES } from "reusable/lib/Alert"; | |
import { useHistory } from "react-router"; | |
export default function useAlert() { | |
const history = useHistory(); | |
const { setAlerts } = useContext(AlertContext); |
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 { useEffect, useRef, useState } from "react"; | |
/** | |
* Provides the functionality of React.useState() with the only difference that | |
* it sets a state only if its parent component is still mounted, aka "safe setState". | |
*/ | |
export default function useSafeState(initialState) { | |
const mountedRef = useRef(false); | |
const [state, setState] = useState(initialState); |