|
|
@ -2,59 +2,31 @@ import withPage from "@/base/withPage" |
|
|
|
import { Hero } from "@/ui/Hero" |
|
|
|
import { Button } from "@blueprintjs/core" |
|
|
|
import { ReactNode, useCallback } from "react" |
|
|
|
import { Fly } from "@/plugins/request" |
|
|
|
// import { Fly } from "@/plugins/request"
|
|
|
|
import { toast } from "react-toastify" |
|
|
|
import { useForm, SubmitHandler } from "react-hook-form"; |
|
|
|
|
|
|
|
interface IProps { |
|
|
|
children: ReactNode |
|
|
|
} |
|
|
|
|
|
|
|
type Inputs = { |
|
|
|
example: string, |
|
|
|
exampleRequired: string, |
|
|
|
}; |
|
|
|
|
|
|
|
// export default withPage(function Project({ }: IProps) {
|
|
|
|
|
|
|
|
// const onClick = useCallback(() => {
|
|
|
|
// toast.success("Wow so easy !")
|
|
|
|
// // Fly.invoke().request<{a: number}>({
|
|
|
|
// // method: "get",
|
|
|
|
// // url: "http://api.juheapi.com/japi/toh",
|
|
|
|
// // global: false
|
|
|
|
// // }).then((res) => console.log(res.data)).catch(console.log)
|
|
|
|
// }, [])
|
|
|
|
|
|
|
|
// return (
|
|
|
|
// <>
|
|
|
|
// <Hero></Hero>
|
|
|
|
|
|
|
|
// <div className="container">
|
|
|
|
// <Button onClick={onClick}>请求</Button>
|
|
|
|
// </div>
|
|
|
|
// </>
|
|
|
|
// )
|
|
|
|
// })
|
|
|
|
|
|
|
|
export default withPage(function Project({ }: IProps) { |
|
|
|
const { register, handleSubmit, watch, formState: { errors } } = useForm<Inputs>(); |
|
|
|
const onSubmit: SubmitHandler<Inputs> = data => console.log(data); |
|
|
|
|
|
|
|
console.log(watch("example")) // watch input value by passing the name of it
|
|
|
|
const onClick = useCallback(() => { |
|
|
|
toast.success("Wow so easy !") |
|
|
|
// Fly.invoke().request<{a: number}>({
|
|
|
|
// method: "get",
|
|
|
|
// url: "http://api.juheapi.com/japi/toh",
|
|
|
|
// global: false
|
|
|
|
// }).then((res) => console.log(res.data)).catch(console.log)
|
|
|
|
}, []) |
|
|
|
|
|
|
|
return ( |
|
|
|
/* "handleSubmit" will validate your inputs before invoking "onSubmit" */ |
|
|
|
<form onSubmit={handleSubmit(onSubmit)}> |
|
|
|
{/* register your input into the hook by invoking the "register" function */} |
|
|
|
<input defaultValue="test" {...register("example")} /> |
|
|
|
|
|
|
|
{/* include validation with required or other standard HTML validation rules */} |
|
|
|
<input {...register("exampleRequired", { required: true })} /> |
|
|
|
{/* errors will return when field validation fails */} |
|
|
|
{errors.exampleRequired && <span>This field is required</span>} |
|
|
|
|
|
|
|
<input type="submit" /> |
|
|
|
</form> |
|
|
|
); |
|
|
|
<> |
|
|
|
<Hero></Hero> |
|
|
|
|
|
|
|
<div className="container"> |
|
|
|
<Button onClick={onClick}>请求</Button> |
|
|
|
</div> |
|
|
|
</> |
|
|
|
) |
|
|
|
}) |
|
|
|