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 { getUser } from "../api/api" | |
interface User { | |
name: string; | |
email: string; | |
age: 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 * as React from "react"; | |
import "./styles.css"; | |
import useTest from "./hook"; | |
export default function App() { | |
const [getUser, user, errorMessage] = useTest(); | |
return ( | |
<div className="App"> | |
<h1>Simple API Hook Demo</h1> | |
<button onClick={() => getUser("123")}>Get User</button> |
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 { getResource } from "./api"; | |
export default <T>(): [(url: string) => void, string, T?] => { | |
const [response, setResponse] = useState<T>(); | |
const [errorMsg, setErrorMsg] = useState(""); | |
const getResponseTest = async (url: string) => { | |
try { |
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 * as React from "react"; | |
import "./styles.css"; | |
import useTest from "./hook"; | |
interface User { | |
name: string; | |
email: string; | |
age: 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 * as React from "react"; | |
import "./styles.css"; | |
import useTest from "./hook"; | |
interface Invoice { | |
id: string | |
amount: number | |
url: string | |
} |
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" | |
const MyPage = () => { | |
return ( | |
<div> | |
<div> | |
<p>Admin text</p> | |
</div> | |
<div> | |
<p>Manager text</p> |
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 { useSelector } from "react-redux" | |
enum Permission { | |
PERMISSION_NONE = 0x0, | |
PERMISSION_ADMIN = 0x1, | |
PERMISSION_MANAGER = 0x2, |
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
interface IProps { | |
permission: Permission | |
} | |
const PermissionWrapper: React.FC<IProps> = ({ permission, children }) => { | |
const status = useSelector((state: IRootState) => state.account.status) | |
if (permission & status) { | |
return <>{children}</> | |
} |
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 MyPage = () => { | |
return ( | |
<div> | |
<PermissionWrapper permission={Permission.PERMISSION_ADMIN}> | |
<div> | |
<p>Admin text</p> | |
</div> | |
</PermissionWrapper> | |
<PermissionWrapper permission={Permission.PERMISSION_MANAGER}> |
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 { OutlinedTextFieldProps, TextField } from "@material-ui/core" | |
import React, { FC, useEffect, useState } from "react" | |
interface IProps extends OutlinedTextFieldProps { | |
waitForInput?: boolean | |
} | |
const ExtendedInput: FC<IProps> = (props) => { | |
const { waitForInput, ...inputProps } = props | |
const [waitEvent, setWaitEvent] = useState<React.ChangeEvent<HTMLInputElement>>(null) |
OlderNewer