投稿時間:2022-12-18 10:16:06 RSSフィード2022-12-18 10:00 分まとめ(18件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
AWS lambdaタグが付けられた新着投稿 - Qiita S3オブジェクトをトリガーにした zip展開するLambda構築ハンズオン https://qiita.com/i3no29/items/672a53620c42228021fa lambda 2022-12-18 09:54:39
python Pythonタグが付けられた新着投稿 - Qiita Prefectを試用した https://qiita.com/yoshitake_tatsuhiro/items/8a066d106a7d32bc41d0 android 2022-12-18 09:44:15
python Pythonタグが付けられた新着投稿 - Qiita MLOpsにおけるML-based Software Delivery Metrics https://qiita.com/emi_ndk/items/67ce82ad3707509f3894 mlops 2022-12-18 09:34:07
js JavaScriptタグが付けられた新着投稿 - Qiita 育児に「ぴよログ」使ったのでログファイルをJavaScriptで扱いやすくしてみた https://qiita.com/tkyko13/items/2e9d166cdbdaf01eb569 iotlt 2022-12-18 09:04:33
AWS AWSタグが付けられた新着投稿 - Qiita S3オブジェクトをトリガーにした zip展開するLambda構築ハンズオン https://qiita.com/i3no29/items/672a53620c42228021fa lambda 2022-12-18 09:54:39
AWS AWSタグが付けられた新着投稿 - Qiita 最近書いたコスパのよいシェルスクリプト(ターミナルから離れずに翻訳) https://qiita.com/narutaro/items/4ed72078be18a2eea254 amazontranslate 2022-12-18 09:45:23
AWS AWSタグが付けられた新着投稿 - Qiita AWS CDK公式チュートリアル実況プレイ(VPC編) https://qiita.com/togo_mentor/items/7087e403ec30082fe092 awscdk 2022-12-18 09:28:47
Docker dockerタグが付けられた新着投稿 - Qiita Railsで必要十分なAPI開発環境を整える(Docker + Rails + MySQL + OpenAPI + CircleCI) https://qiita.com/sho-19202325/items/57da8b494d0dd188e3b5 Railsで必要十分なAPI開発環境を整えるDockerRailsMySQLOpenAPICircleCIはじめにRailsでAPIを作るぞってなった時にいつも行っているテストやリンターなどの導入手順を備忘録がてら記事にしました。 2022-12-18 09:02:33
Ruby Railsタグが付けられた新着投稿 - Qiita Railsで必要十分なAPI開発環境を整える(Docker + Rails + MySQL + OpenAPI + CircleCI) https://qiita.com/sho-19202325/items/57da8b494d0dd188e3b5 Railsで必要十分なAPI開発環境を整えるDockerRailsMySQLOpenAPICircleCIはじめにRailsでAPIを作るぞってなった時にいつも行っているテストやリンターなどの導入手順を備忘録がてら記事にしました。 2022-12-18 09:02:33
海外TECH DEV Community Simple React-Hook-Form v7 Tutorial with Typescript https://dev.to/pranavb6/simple-react-hook-form-v7-tutorial-with-typescript-j78 Simple React Hook Form v Tutorial with TypescriptHere is the repo with starter code if you want to follow along Part Basic FormLet s get started with some basic code import App css function App const onSubmitHandler e React FormEvent lt HTMLFormElement gt gt e preventDefault console log Submitted return lt main className main prose gt lt h gt Forms lt h gt lt form onSubmit onSubmitHandler className form gt lt div gt lt label htmlFor fullName gt Full Name lt label gt lt input name fullName id fullName type text gt lt div gt lt div gt lt label htmlFor food gt Select Your Favourite Food lt label gt lt select name food id food gt lt option value disabled gt Please Select lt option gt lt option value pizza gt Pizza lt option gt lt option value burger gt Burger lt option gt lt option value ice cream gt Ice Cream lt option gt lt select gt lt div gt lt div gt lt input name approvesTutorial id approves tutorial type checkbox gt lt label htmlFor approves tutorial gt Do you approve this tutorial lt label gt lt div gt lt button type submit gt Submit lt button gt lt form gt lt main gt export default App To make the form look good I ve added some custom TailwindCSS classes so here is how it looks Part Integrating Inputs With React Hook FormNext we are going to define an interface that represents our form interface UserInput fullName string food string approvesTutorial boolean Note that the keys of our interface correspond with the names of our fieldsNext let s call the useForm hook from react hook formimport useForm from react hook form function App const register useForm lt UserInput gt By giving the useForm hook our UserInput interface react hook form can understand our form better and give us typesafety with it The register function allows us to register an input so let s register one of our fields Before lt input name fullName id fullName type text gt After lt input register fullName id fullName type text gt Note that we can get rid of the name prop since the register fullName also provides the name propNow lets register all of our inputs and select lt div gt lt label htmlFor fullName gt Full Name lt label gt lt input register fullName id fullName type text gt lt div gt lt div gt lt label htmlFor food gt Select Your Favourite Food lt label gt lt select register food id food gt lt option value disabled gt Please Select lt option gt lt option value pizza gt Pizza lt option gt lt option value burger gt Burger lt option gt lt option value ice cream gt Ice Cream lt option gt lt select gt lt div gt lt div gt lt input register approvesTutorial id approves tutorial type checkbox gt lt label htmlFor approves tutorial gt Do you approve this tutorial lt label gt lt div gt Note that the name we pass into our register function must be a key of our UserInput interface we if try to pass in a name that s not in our UserInput interface such as register fullName typescript will complain which is great This is all because we pass in our interface to the useForm hook ie useForm lt UserInput gt Part Configuring the Submit FunctionalityWe also need to let react hook form handle the submit functionality To do this let s get the handleSubmit function from the useForm hook and pass it to the form s onSubmit prop We can then pass in our own onSubmitHandler to the handleSubmit function That was a mouthful so let s just show it function App const register handleSubmit useForm lt UserInput gt const onSubmitHandler values UserInput gt console log Submitted console table values return lt form onSubmit handleSubmit onSubmitHandler className form gt lt form gt Let s check out the console logs Awesome we have a working form with react hook form Note how the onSubmitHandler takes in a values parameter of type UserInput Because we told useForm to use our UserInput interface it knows that the values submitted by our form will be of type UserInput Part Adding Default ValuesNext let s setup some default values const defaultValues UserInput fullName John Doe food approvesTutorial true function App const register handleSubmit useForm lt UserInput gt defaultValues We can pass in default values right into the useForm hook Here is a screenshot after I added in the default values Part Error handlingNext let s add in some error handling react hook form ships with some built in error handling which you can pass into the register function like so register fullName required true maxLenfth but its not as powerful as libraries like yup Luckily react hook form can integrate with libraries like yup Let s import yup and create a validation schema for our form import as yup from yup const validationSchema yup object fullName yup string required Full Name is required food yup string required Food is required approvesTutorial yup boolean required Approves Tutorial is required To integrate our yup validationSchema with react hook form we need to first import yupResolver from the hookform resolvers package and then call the yupResolver function and finally pass it into the useForm hook import as yup from yup import yupResolver from hookform resolvers yup const validationSchema yup object fullName yup string required Full Name is required food yup string required Food is required approvesTutorial yup boolean required Approves Tutorial is required function App const register handleSubmit useForm lt UserInput gt defaultValues resolver yupResolver validationSchema Now you can see our form doesn t submit until the validation schema is satisfied However we don t actually see the errors We need to get the errors object from the formState object in the useForm hook like so const register handleSubmit formState errors get errors useForm lt UserInput gt defaultValues resolver yupResolver validationSchema We can view the error message by getting the errors lt field name gt message like so errors fullName amp amp lt p className error message gt errors fullName message lt p gt Now let s add an error message to all the fields lt div gt lt label htmlFor fullName gt Full Name lt label gt lt input register fullName id fullName type text gt errors fullName amp amp lt p className error message gt errors fullName message lt p gt lt div gt lt div gt lt label htmlFor food gt Select Your Favourite Food lt label gt lt select register food id food gt lt option value disabled gt Please Select lt option gt lt option value pizza gt Pizza lt option gt lt option value burger gt Burger lt option gt lt option value ice cream gt Ice Cream lt option gt lt select gt errors food amp amp lt p className error message gt errors food message lt p gt lt div gt lt div gt lt input register approvesTutorial id approves tutorial type checkbox gt lt label htmlFor approves tutorial gt Do you approve this tutorial lt label gt errors approvesTutorial amp amp lt p className error message gt errors approvesTutorial message lt p gt lt div gt Note that we can only see the errors after we press the submit button This is because the mode property of the useForm hook is set to onSubmit by default which means it will start validation on a submit event and then trigger every time a field is changed We can change this to onTouched which will start validation the first time a user clicks out of an input aka onBlur and then trigger every time a field is changed const register handleSubmit formState errors get errors of the form useForm lt UserInput gt defaultValues resolver yupResolver validationSchema mode onTouched default is onSubmit Now we can see some beautiful errors Because of how powerful yup is we can even require the checkbox field to be trueconst validationSchema yup object fullName yup string required Full Name is required max Name is too long food yup string required Food is required approvesTutorial yup boolean isTrue You must approve of this tutorial required Approves tutorial is required Now we can see the following error Here is the full final code import useForm from react hook form import App css import as yup from yup import yupResolver from hookform resolvers yup interface UserInput fullName string food string approvesTutorial boolean const defaultValues UserInput fullName John Doe food approvesTutorial true const validationSchema yup object fullName yup string required Full Name is required max Name is too long food yup string required Food is required approvesTutorial yup boolean isTrue You must approve of this tutorial required Approves tutorial is required function App const register handleSubmit formState errors get errors of the form useForm lt UserInput gt defaultValues resolver yupResolver validationSchema mode onTouched default is onSubmit const onSubmitHandler values UserInput gt console log Submitted console table values return lt main className main prose gt lt h gt Forms lt h gt lt form onSubmit handleSubmit onSubmitHandler className form gt lt div gt lt label htmlFor fullName gt Full Name lt label gt lt input register fullName id fullName type text gt errors fullName amp amp lt p className error message gt errors fullName message lt p gt lt div gt lt div gt lt label htmlFor food gt Select Your Favourite Food lt label gt lt select register food id food gt lt option value disabled gt Please Select lt option gt lt option value pizza gt Pizza lt option gt lt option value burger gt Burger lt option gt lt option value ice cream gt Ice Cream lt option gt lt select gt errors food amp amp lt p className error message gt errors food message lt p gt lt div gt lt div gt lt input register approvesTutorial id approves tutorial type checkbox gt lt label htmlFor approves tutorial gt Do you approve this tutorial lt label gt errors approvesTutorial amp amp lt p className error message gt errors approvesTutorial message lt p gt lt div gt lt button type submit gt Submit lt button gt lt form gt lt main gt export default App This is everything you need to know to get started using react hook form I hope you enjoy using it as much as I have This is my first tutorial I hope you enjoyed reading and let me know if I made any mistakes or how I could improve it I would appreciate some constructive criticism 2022-12-18 00:18:26
ニュース @日本経済新聞 電子版 「Snapchat」欧米でZ世代の9割利用 日本展開の戦略は https://t.co/TwbnW6WqT4 https://twitter.com/nikkei/statuses/1604275708775522304 snapchat 2022-12-18 00:41:49
ニュース @日本経済新聞 電子版 モロッコ、紙一重の4位 「ホーム」でW杯盛り上げ役に https://t.co/2C8PaH4GOd https://twitter.com/nikkei/statuses/1604271553977339905 紙一重 2022-12-18 00:25:19
海外ニュース Japan Times latest articles A musical history told through centuries of Japanese literature https://www.japantimes.co.jp/news/2022/12/18/national/history/musical-history-told-centuries-japanese-literature/ cacophony 2022-12-18 09:30:08
ニュース BBC News - Home Steven Spielberg regrets decimation of shark population after Jaws https://www.bbc.co.uk/news/entertainment-arts-64011888?at_medium=RSS&at_campaign=KARANGA fears 2022-12-18 00:09:07
ニュース BBC News - Home The Papers: New strike threats and Sussexes ‘want apology’ https://www.bbc.co.uk/news/blogs-the-papers-64015275?at_medium=RSS&at_campaign=KARANGA family 2022-12-18 00:48:57
北海道 北海道新聞 深川市長選に3氏が届け出 2007年以来の選挙戦に https://www.hokkaido-np.co.jp/article/776766/ 任期満了 2022-12-18 09:50:59
北海道 北海道新聞 勾留中の男性死亡、大阪府警 戒具で拘束も、死因調べる https://www.hokkaido-np.co.jp/article/776740/ 大阪府警 2022-12-18 09:37:07
北海道 北海道新聞 モロッコ旋風に幕、地元称賛 初の4強「感動もらった」 https://www.hokkaido-np.co.jp/article/776748/ 称賛 2022-12-18 09:20:15

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)