This file contains hidden or 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" | |
| export class LoadDataClass extends React.Component { | |
| componentDidMount(): void { | |
| fetch("/some-data.json") | |
| .then((response) => response.json()) | |
| .then((data) => { | |
| this.setState({ data }) | |
| }) | |
| } |
This file contains hidden or 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, useState } from "react" | |
| export const LoadDataFunction = () => { | |
| const [data, setData] = useState() | |
| useEffect(() => { | |
| fetch("/some-data.json") | |
| .then((response) => response.json()) | |
| .then((data) => { | |
| setData(data) |
This file contains hidden or 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
| useEffect(() => { | |
| const controller = new AbortController() | |
| fetch("/some-data.json", { signal: controller.signal }) | |
| .then((response) => response.json()) | |
| .then((data) => { | |
| setData(data) | |
| }) | |
| return () => { |
This file contains hidden or 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, useState } from "react" | |
| const useMedia = (query: string): boolean => { | |
| const [matches, setMatches] = useState(false) | |
| useEffect(() => { | |
| const queryObject = window.matchMedia(query) | |
| setMatches(queryObject.matches) | |
| const listener = (e: MediaQueryListEvent) => { |
OlderNewer