投稿時間:2022-05-22 00:19:53 RSSフィード2022-05-22 00:00 分まとめ(24件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
AWS AWS Japan Blog 地震の分析をスケールさせる:地震は防げないが、より良い備えをクラウドで行う https://aws.amazon.com/jp/blogs/news/unleashing-seismic-modeling-at-scale-we-cant-stop-quakes-but-we-can-be-better-prepared/ この高速化により、研究者は同じ周波数でより多くのシミュレーションを行うために必要な速度を得ることができ、より徹底的に被災シナリオを比較検討することができるようになりました。 2022-05-21 14:54:53
python Pythonタグが付けられた新着投稿 - Qiita Python+Pillowで、任意の文字列を画像で出力する https://qiita.com/YoshikiIto/items/ace92dc9b05e375b8326 pythonpillow 2022-05-21 23:14:53
python Pythonタグが付けられた新着投稿 - Qiita オレオレサイト内通貨を作るAPIを作りました https://qiita.com/Domao/items/cf838896128d5c35afdd 作りました 2022-05-21 23:10:51
Ruby Rubyタグが付けられた新着投稿 - Qiita FizzBuzz https://qiita.com/ryo-he/items/f1f3556723f4c7056c63 fizzbuzzfizzbuzzfizzbuzz 2022-05-21 23:22:27
Docker dockerタグが付けられた新着投稿 - Qiita VSCodeのデバッグ機能を使える人になる https://qiita.com/829yasubee/items/21ad0390b559f75eab16 docker 2022-05-21 23:59:40
Git Gitタグが付けられた新着投稿 - Qiita Web開発現場でよく使いそうなVSCodeの機能をまとめたみた https://qiita.com/NegishiYuya/items/bf1d9597b152515bca60 visualstudio 2022-05-21 23:39:10
技術ブログ Developers.IO [Node.js / TypeScript] Amazon CognitoのJWTをデコードする、JWTを作成してテストする https://dev.classmethod.jp/articles/nodejs-typescript-decode-a-jwt-of-amazon-cognito-create-a-jwt-for-testing/ amazoncognito 2022-05-21 14:53:49
技術ブログ Developers.IO BigQuery リモート関数で Natural Language API を使って、SQL でお客様レビューの感情分析してみた。 https://dev.classmethod.jp/articles/bigquery-remote-function-with-natural-language-api/ bigquery 2022-05-21 14:23:48
海外TECH MakeUseOf How to Build a DIY Solid-State Relay Using a TRIAC https://www.makeuseof.com/how-to-build-diy-solid-state-relay-using-triac/ automation 2022-05-21 14:30:13
海外TECH MakeUseOf How to Run Anything You Download Securely With Sandboxie Plus for Windows https://www.makeuseof.com/windows-sandboxie-plus-guide/ sandboxie 2022-05-21 14:15:13
海外TECH MakeUseOf What Happened to IGTV on Instagram? https://www.makeuseof.com/what-happened-to-igtv-on-instagram/ video 2022-05-21 14:05:14
海外TECH DEV Community Build end-to-end typesafe APIs with tRPC https://dev.to/nexxeln/build-end-to-end-typesafe-apis-with-trpc-3o3f Build end to end typesafe APIs with tRPCtRPC is a tool that provides type safety between your front and back ends hence it makes it really easy to build scalable and robust backends quickly for your Next js and Node apps In this article we will be looking at what tRPC is and how to set it up and use it with Next js What is tRPC tRPC is a very light library which lets you build fully typesafe APIs without the need of schemas or code generation It allows sharing of types between the client and server and just imports the types and not the actual server code so none of the server code is exposed in the frontend With end to end type safety you re able to catch errors between your frontend and backend at compile and build time Currently the dominant way of making typesafe APIs is using GraphQL it s awesome Since GraphQL is a query language for APIs it doesn t take full advantage of TypeScript it comes with excess boilerplate code and requires a lot of initial setup If you re already using TypeScript everywhere you can share types directly between the client and the server without the need of any code generation Installing tRPC in Next jsLets first create a Next js project with TypeScript npx create next app next with trpc tsLet s now use the recommended folder structure by tRPC Open the project in your favourite editor make a src directory and move the pages and styles directory inside it Your folder structure should look something like this ├ーsrc│├ーpages││├ー app tsx││├ーapi│││││└ー └ー Once this is done let s install tRPC npm i trpc client trpc server trpc react trpc next zod react querytRPC is a built on top of react query which is a package for fetching caching and updating data without the need of any global state We are also using zod for schema and input validations You can also use other validation libraries like yup Superstruct etc Read more Also make sure that in your tsconfig json strict mode is enabled tsconfig json compilerOptions strict true This is so that zod can run correctly and in general having strict mode enabled is just good Creating our serverOur tRPC server will be deployed as a Next js API route This code only runs on the server so it doesn t affect the bundle sizes in any way Creating our contextLet s first create a directory inside src called server In here we need to first create a context Create a file called context ts and add the following code to it src server context tsimport CreateNextContextOptions from trpc server adapters next import inferAsyncReturnType from trpc server export async function createContext ctxOptions CreateNextContextOptions const req ctxOptions req const res ctxOptions res return req res export type MyContextType inferAsyncReturnType lt typeof createContext gt This will be available as ctx in all our resolvers which we ll write in a bit Right now we re just passing the request and response to our routes but you can add other things like JWT tokens cookies or even Prisma Client code Creating our routerNow let s create a file called createRouter ts in the server directory We ll be setting up a simple router Copy the following code to it src server createRouter tsimport as trpc from trpc server import type MyContextType from context export function createRouter return trpc router lt MyContextType gt Creating our routesLet s create a new directory inside src server called routers Make a file called app ts inside it This will be the root route src server routers app tsimport createRouter from createRouter export const appRouter createRouter export type AppRouter typeof appRouter Now let s create a router that takes a name as input and returns it to the client Add a file called name ts src server routers name tsimport z from zod import createRouter from createRouter export const nameRouter createRouter query getName input z object name z string nullish nullish resolve input return greeting Hello input name world Just like GraphQL tRPC uses queries and mutations A query is used for fetching data and mutations are used to create update and delete data Here we are creating a query to get a name The name of our query is getName Here input takes the user input which is validated using zod When this endpoint is requested the resolve function is called and it returns the hello world greeting because why not Now let s merge this route in our root route Come back to app ts and add the following code src server routers app tsimport createRouter from createRouter import nameRouter from name export const appRouter createRouter merge names nameRouter export type AppRouter typeof appRouter That at the end of names is intentional for reasons you ll see soon Creating our Next js API routeLet s create a trpc directory inside src pages api Inside it create a file called trpc ts Just a reminder of our folder structure ├ーsrc│├ーpages││├ー app tsx ││├ーapi│││└ーtrpc│││└ー trpc ts ││└ー │├ーserver││├ーrouters│││├ーapp ts │││├ーname ts │││└ー ││├ーcontext ts ││└ーcreateRouter ts └ー Here we will implement our tRPC router As I had said before our server will be deployed as a Next js API route src pages api trpc trpc tsimport createNextApiHandler from trpc server adapters next import appRouter from server routers app import createContext from server context export default createNextApiHandler router appRouter createContext batching enabled true onError error if error code INTERNAL SERVER ERROR console error Something went wrong error We re passing it our router our createConext function enabling batching and logging errors With that we re pretty much done with the backend Let s now work on our frontend Calling our tRPC API routesLet s now connect our backend with our frontend Go to src pages app tsx Here we are going to configure tRPC and React Query Copy the following code src pages app tsimport AppType from next dist shared lib utils import withTRPC from trpc next import AppRouter from api trpc trpc import styles globals css const MyApp AppType Component pageProps gt return lt Component pageProps gt const getBaseUrl gt if process browser return if process env NEXT PUBLIC VERCEL URL return https process env NEXT PUBLIC VERCEL URL return http localhost process env PORT export default withTRPC lt AppRouter gt config ctx const url getBaseUrl api trpc return url ssr false MyApp We re also setting ssr Server Side Rendering to be false for now Next create a utils directory inside src Inside utils create a file called trpc ts Folder structure for reference ├ーsrc│├ーpages││├ー app tsx ││├ーapi│││└ーtrpc│││└ー trpc ts ││└ー │├ーserver││├ーrouters│││├ーapp ts │││├ーname ts │││└ー ││├ーcontext ts ││└ーcreateRouter ts └ーutils│└ーtrpc ts└ー Here we re going to create a hook to use tRPC on the client src utils trpc tsimport createReactQueryHooks from trpc react import inferProcedureOutput from trpc server import AppRouter from server routers app export const trpc createReactQueryHooks lt AppRouter gt export type inferQueryOutput lt TRouteKey extends keyof AppRouter def queries gt inferProcedureOutput lt AppRouter def queries TRouteKey gt This hook is strongly typed using our API type signature This is what enables the end to end typesafety in our code For example if we change a router s name in the backend it will show an error in the frontend where we re calling the route It allows us to call our backend and get fully typed inputs and outputs from it It also gives us wonderful autocomplete Let s now actually use our query that we defined earlier Go to the index page and instead of copy pasting this code block type it yourself to experience the magic of tRPC The autocomplete is just crazy src pages index tsximport trpc from utils trpc export default function Name const nameQuery trpc useQuery names getName name nexxel return lt gt nameQuery data lt h gt nameQuery data greeting lt h gt lt span gt Loading lt span gt lt gt Did you see the magic In case you re lazy and just copied the code I got you covered Look at this The autocomplete is soo good And it catches any kind of type errors you make without the need of declaring any types or interfaces manually It s crazy good Now start the dev server and see the greeting on the screen Notice the loading state This is because we set ssr to false when we configured tRPC in app tsx So it s being client side rendered Go to src pages app tsx and set ssr to true now and see what happens Now there is no loading state because the data is being fetched server side and then it is being rendered You can use whatever suits your needs ConclusionIn this article we looked at what tRPC is and how to use it with a Next JS app tRPC makes building typesafe APIs incredibly easy and improves the DX by a million times You can use it with not only Next js but also React Node and there s adapters being developed for Vue and Svelte as well I recommend using it for pretty much any project you make now For more information checkout the tRPC docs Code Thank you for reading 2022-05-21 14:06:27
Apple AppleInsider - Frontpage News Daily deals May 21: $100 off 11-inch iPad Pro, $173 Cuisinart Pizza Oven, $100 Linksys Mesh Wi-Fi https://appleinsider.com/articles/22/05/21/daily-deals-may-21-100-off-11-inch-ipad-pro-173-cuisinart-pizza-oven-100-linksys-mesh-wi-fi?utm_medium=rss Daily deals May off inch iPad Pro Cuisinart Pizza Oven Linksys Mesh Wi FiAlongside off an inch iPad Pro Saturday s best deals include Razer Anzu Smart Glasses a inch Toshiba Smart TV for a Polk Audio soundbar and much more Best deals May Every day AppleInsider checks online stores for discounts and deals on a variety of items including Apple products smart TVs cameras and accessories The best items are put together in our daily deals list Read more 2022-05-21 14:57:00
Apple AppleInsider - Frontpage News Compared: OnePlus 10 Pro vs iPhone 13 Pro & iPhone 13 Pro Max https://appleinsider.com/articles/22/03/05/comparison-oneplus-10-pro-vs-iphone-13-pro-iphone-13-pro-max?utm_medium=rss Compared OnePlus Pro vs iPhone Pro amp iPhone Pro MaxWe got our hands on the new OnePlus Pro and compared to Apple s latest iPhone Pro line for this in depth showdown The OnePlus Pro directly competes with the iPhone Pro seriesAfter going on sale in China OnePlus used Mobile World Congress to reveal it is bringing the OnePlus Pro to other regions worldwide It intends to release the model in North America India and Europe by the end of March among other expansions Read more 2022-05-21 14:29:30
ニュース BBC News - Home Trooping the Colour: Injuries as part of stand collapses https://www.bbc.co.uk/news/uk-england-london-61533968?at_medium=RSS&at_campaign=KARANGA guards 2022-05-21 14:50:51
ニュース BBC News - Home Abertillery boy, 11, loses finger allegedly fleeing bullies https://www.bbc.co.uk/news/uk-wales-61535184?at_medium=RSS&at_campaign=KARANGA bulliesraheem 2022-05-21 14:08:14
ニュース BBC News - Home Australia election: Anthony Albanese leads Labor to Australian election victory https://www.bbc.co.uk/news/world-australia-61267489?at_medium=RSS&at_campaign=KARANGA government 2022-05-21 14:38:57
ニュース BBC News - Home Kylian Mbappe: Paris St-Germain forward agrees in principle to stay at French champions https://www.bbc.co.uk/sport/football/61528610?at_medium=RSS&at_campaign=KARANGA madrid 2022-05-21 14:41:54
ニュース BBC News - Home Diamond League: Dina Asher-Smith wins her first 100m of season in Birmingham https://www.bbc.co.uk/sport/av/athletics/61536987?at_medium=RSS&at_campaign=KARANGA Diamond League Dina Asher Smith wins her first m of season in BirminghamWatch highlights as Great Britain s m world champion Dina Asher Smith wins the women s m at the Diamond League in Birmingham 2022-05-21 14:18:05
サブカルネタ ラーブロ 支那ソバ 玉龍 (GYOKURYU)@昭島市<ワンタン麺(海老・塩)> http://ra-blog.net/modules/rssc/single_feed.php?fid=199309 支那ソバ玉龍GYOKURYU昭島市ltワンタン麺海老・塩gt訪問日メニューワンタン麺海老塩変更味塩コメント今日紹介するのは、拝島駅から昭島方面に向かったヨーカドーの裏手にある「玉龍」。 2022-05-21 15:32:10
北海道 北海道新聞 米、5兆円追加支援法成立 大統領署名、ウクライナに https://www.hokkaido-np.co.jp/article/683785/ 米大統領 2022-05-21 23:32:00
北海道 北海道新聞 米で滑落死は山岳カメラマン 山梨出身の平賀淳さん https://www.hokkaido-np.co.jp/article/683774/ 国立公園 2022-05-21 23:05:46
北海道 北海道新聞 ロシアがバイデン氏らの入国禁止 ウクライナ関連制裁に報復 https://www.hokkaido-np.co.jp/article/683779/ 入国禁止 2022-05-21 23:14:00
北海道 北海道新聞 佐呂間で28・3度 北海道内で気温上昇 https://www.hokkaido-np.co.jp/article/683778/ 北海道内 2022-05-21 23:05:38

コメント

このブログの人気の投稿

投稿時間: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件)