投稿時間:2023-03-19 01:13:27 RSSフィード2023-03-19 01:00 分まとめ(14件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita 【試作】Raspberry Piを使った監視カメラ https://qiita.com/marumen/items/b1ed78f8d1f1cc6e1d2f mstickc 2023-03-19 00:56:13
python Pythonタグが付けられた新着投稿 - Qiita Polarsでjsonlファイルを読み書きする https://qiita.com/UMA821/items/876ce67fa6bf940dd029 jsonl 2023-03-19 00:43:41
Ruby Rubyタグが付けられた新着投稿 - Qiita 【Mac】rbenv を導入して Ruby のインストールとバージョン管理を簡単にする https://qiita.com/to3izo/items/1895b3f13d3c0409b905 rbenv 2023-03-19 00:57:39
AWS AWSタグが付けられた新着投稿 - Qiita AWSわからない単語 https://qiita.com/yuta_3737/items/2357ff25a2aa7a1b27da vpcvirtualprivatecloud 2023-03-19 00:26:15
海外TECH MakeUseOf 6 Ways to Find a Raspberry Pi's IP Address https://www.makeuseof.com/ways-to-find-raspberry-pi-ip-address/ addressto 2023-03-18 15:30:17
海外TECH MakeUseOf 7 Ways to Fix the "Steam Must Be Running to Play This Game" Error in Windows 11 https://www.makeuseof.com/steam-must-be-running-error-windows-11/ Ways to Fix the amp quot Steam Must Be Running to Play This Game amp quot Error in Windows Are your Steam games claiming that Steam isn t running even while it s open Here s how to fix it on Windows 2023-03-18 15:16:15
海外TECH DEV Community Paracetamol.js💊| #208: Explica este código JavaScript https://dev.to/duxtech/paracetamoljs-208-explica-este-codigo-javascript-3b29 Paracetamol js Explica este código JavaScript Explica este código JavaScript Dificultad Intermedioconst one gt return new Promise resolve reject gt setTimeout gt resolve one const two gt return new Promise resolve reject gt setTimeout gt reject new Error Error const res gt return Promise allSettled one two res then x gt console log x catch err gt console log err A status fulfilled value one status rejected reason Error después de s B status fulfilled value one status fulfilled value two después de s C Promise lt rejected gt D Ninguna de las anterioresRespuesta en el primer comentario 2023-03-18 15:15:57
海外TECH DEV Community Building a Fullstack Next.js app -> tRPC(v10), Tailwind, Prisma https://dev.to/kharioki/building-a-fullstack-nextjs-app-trpcv10-tailwind-prisma-2f4 Building a Fullstack Next js app gt tRPC v Tailwind PrismaI made this write up as a follow up to Francisco Mendes post While the post is a great way to get introduced to building with end to end type safety in Nextjs it was written on v of tRPC and as at this writing a lot has changed with v I ll cover the same app setup the only changes will be tRPC setup will follow the current v as at this writing configurations Let s get to it What are the tools we ll use gt tRPC Prisma ZodtRPC Is a toolkit that enables us to build totally type safe applications by only using inference It s a great tool for building APIs and it s very easy to use Prisma is an ORM that enables us to write type safe queries to our database It is a server side library that helps developers read and write data to the database in an intuitive efficient and safe way It is easy to integrate into your framework of choice gt Next js Graphql Apollo nest Express e t c Prisma simplifies database access saves repetitive CRUD boilerplate and increases type safety Its the perfect companion for building production grade robust and scalable web applications Zod is a TypeScript first schema builder for data validation and parsing It s a great tool for validating data before it gets to the database It s very easy to use and it s very fast PrerequisitesOf course you ll need basic knowledge of NodeTypescriptNext jsTailwindNpmOkay let s do this Of course I ll add a link to the github repo at the bottom Getting Started Next js setupWe first spin up a next js app and navigate to the project directory note when asked if you want src folder select yes Also select as import alias this tutorial is setup that way npx create next app latest ts grocery listcd grocery list Install and setup Tailwind CSSnpm install fontsource poppinsnpm install D tailwindcss postcss autoprefixernpx tailwindcss init pconfigure paths in the tailwind config js type import tailwindcss Config module exports content src pages js ts jsx tsx src components js ts jsx tsx theme extend plugins Add Tailwind directives to replace the styles in the src styles globals css tailwind base tailwind components tailwind utilities font family Poppins Setup PrismaInstall Prisma and initialize it npm install prismanpx prisma initEdit the schema prisma file as follows generator client provider prisma client js datasource db provider sqlite url file dev db model GroceryList id Int id default autoincrement title String checked Boolean default false Run prisma migration npx prisma migrate dev name initNow we can install prisma client Prisma Client is an auto generated type safe query builder generated based on the models and attributes of your Prisma schema npm install prisma client Configure tRPCNext js makes it easy for you to build your client and server together in one codebase tRPC makes it easy to share types between them ensuring type safety for your application s data fetching Install dependencies npm install trpc server trpc client trpc react query trpc next tanstack react query zod trpc react query provides a thin wrapper around tanstack react query It is required as a peer dependency as an idiomatic way to handle client side caching in React applications Zod for input validation to ensure that our backend only processes requests that fit our API You can use other validation libraries like Yup Superstruct io ts if you prefer Enable strict modeIf you want to use Zod for input validation make sure you have enabled strict mode in your tsconfig json compilerOptions strict true With dependencies installed we can create a server folder and a context ts file to handle our context The context is used to pass contextual data to all router resolvers In this case the context we pass is the prisma instance src server context tsimport as trpc from trpc server import as trpcNext from trpc server adapters next import PrismaClient from prisma client export async function createContext opts trpcNext CreateNextContextOptions const prisma new PrismaClient return prisma export type Context trpc inferAsyncReturnType lt typeof createContext gt Define our routerWith our context created we will now define our router and procedure helpers src server router tsimport initTRPC from trpc server import z from zod import Context from context const t initTRPC context lt Context gt create Base router and procedure helpersconst router t router const publicProcedure t procedure export const serverRouter router findAll publicProcedure query ctx gt return ctx prisma groceryList findMany insertOne publicProcedure input z object title z string mutation input ctx gt return ctx prisma groceryList create data title input title updateOne publicProcedure input z object id z number title z string checked z boolean mutation input ctx gt const id rest input return ctx prisma groceryList update where id data rest deleteAll publicProcedure input z object ids z number array mutation input ctx gt const ids input return ctx prisma groceryList deleteMany where id in ids export type ServerRouter typeof serverRouter We export our serverRouter and its data type ServerTypeNote Avoid exporting the entire t object since it s not very descriptive For instance the use of a t variable is common in in libraries Now we need to create an API route from Next js to which we will handle our handler api We will pass our router and our context which is invoked on every request src pages api trpc trpc tsimport as trpcNext from trpc server adapters next import serverRouter from server router import createContext from server context export default trpcNext createNextApiHandler router serverRouter createContext Now we configure the src pages app tsx fileimport styles globals css import fontsource poppins import type AppType from next app import type ServerRouter from server router import createTRPCNext from trpc next import httpBatchLink from trpc client function getBaseUrl if typeof window undefined return process env VERCEL URL https process env VERCEL URL api trpc http localhost api trpc return api trpc const withTRPC createTRPCNext lt ServerRouter gt config ctx const links httpBatchLink url getBaseUrl return links ssr true const App AppType Component pageProps gt return lt Component pageProps gt export default withTRPC App Then we create a tPRC hook to which we will add the data type of our router as a generic on the createTRPCReact function from react query so that we can make api calls src utils trpc tsimport createReactQueryHooks createTRPCReact from trpc react query import type ServerRouter from server router export const trpc createTRPCReact lt ServerRouter gt Now we are done with most of the work lets build our Frontend Frontend Lets put all the components in one folder src components index tsximport React memo from react import type NextPage from next import GroceryList from prisma client interface CardProps children React ReactNode export const Card NextPage lt CardProps gt children gt return lt div className h screen flex flex col justify center items center bg slate gt children lt div gt export const CardContent NextPage lt CardProps gt children gt return lt div className bg white w md w lg w xl w rounded lg drop shadow md gt children lt div gt interface CardHeaderProps title string listLength number clearAllFn gt void export const CardHeader NextPage lt CardHeaderProps gt title listLength clearAllFn gt return lt div className flex flex row items center justify between p border b border slate gt lt div className flex flex row items center justify between gt lt h className text base font medium tracking wide text gray mr gt title lt h gt lt span className h w bg blue text blue flex items center justify center rounded full text xs gt listLength lt span gt lt div gt lt button className text sm font medium text gray underline type button onClick clearAllFn gt Clear All lt button gt lt div gt export const List NextPage lt CardProps gt children gt return lt div className overflow y auto h gt children lt div gt interface ListItemProps item GroceryList onUpdate item GroceryList gt void const ListItemComponent NextPage lt ListItemProps gt item onUpdate gt return lt div className h border b flex items center justify start px gt lt input type checkbox className h w border gray rounded mr defaultChecked item checked as boolean onChange gt onUpdate item gt lt h className text gray tracking wide text sm gt item title lt h gt lt div gt export const ListItem memo ListItemComponent interface CardFormProps value string onChange e React ChangeEvent lt HTMLInputElement gt gt void submit gt void export const CardForm NextPage lt CardFormProps gt value onChange submit gt return lt div className bg white w md w lg w xl w rounded lg drop shadow md mt gt lt div className relative gt lt input type text className w full py pl pr text sm rounded lg placeholder Grocery item name onChange onChange value value gt lt button type button className absolute p text white translate y bg blue rounded full top right onClick submit gt lt svg className w h xmlns fill none viewBox stroke currentColor gt lt path strokeLinecap round strokeLinejoin round strokeWidth d M vm vm hm H gt lt svg gt lt button gt lt div gt lt div gt We can now import the components and work on our main page src pages index tsximport Head from next head import type NextPage from next import useCallback useState from react import trpc from utils trpc import Card CardContent CardForm CardHeader List ListItem from components import GroceryList from prisma client const Home NextPage gt const itemName setItemName useState lt string gt const data list refetch trpc findAll useQuery const insertMutation trpc insertOne useMutation onSuccess gt refetch const deleteAllMutation trpc deleteAll useMutation onSuccess gt refetch const updateOneMutation trpc updateOne useMutation onSuccess gt refetch const insertOne useCallback gt if itemName return insertMutation mutate title itemName setItemName itemName insertMutation const clearAll useCallback gt if list length deleteAllMutation mutate ids list map item gt item id deleteAllMutation list const updateOne useCallback item GroceryList gt updateOneMutation mutate item checked item checked updateOneMutation return lt gt lt Head gt lt title gt Grocery List lt title gt lt meta name description content Grocery List gt lt link rel icon href favicon ico gt lt Head gt lt main gt lt Card gt lt CardContent gt lt CardHeader title Grocery List listLength list length clearAllFn clearAll gt lt List gt list map item gt lt ListItem key item id item item onUpdate updateOne gt lt List gt lt CardContent gt lt CardForm value itemName onChange e gt setItemName e target value submit insertOne gt lt Card gt lt main gt lt gt export default Home Final result should look like this You can find all this in my repo here I hope this helps you get started with ee type safety 2023-03-18 15:05:34
ニュース BBC News - Home SNP chief executive Peter Murrell resigns over membership row https://www.bbc.co.uk/news/uk-scotland-65000606?at_medium=RSS&at_campaign=KARANGA effect 2023-03-18 15:19:51
ニュース BBC News - Home Kuenssberg: Sunak is now hostage to his promises on childcare and small boats https://www.bbc.co.uk/news/uk-politics-65001267?at_medium=RSS&at_campaign=KARANGA boats 2023-03-18 15:10:08
ニュース BBC News - Home Ex-US President Donald Trump expects to be arrested on Tuesday https://www.bbc.co.uk/news/world-us-canada-65000325?at_medium=RSS&at_campaign=KARANGA donald 2023-03-18 15:44:59
ニュース BBC News - Home Imran Khan court hearing cancelled after clashes in Pakistan capital https://www.bbc.co.uk/news/world-asia-64998922?at_medium=RSS&at_campaign=KARANGA gifts 2023-03-18 15:03:22
ニュース BBC News - Home Motherwell 2-4 Rangers: Visitors fight back in pulsating six-goal thriller https://www.bbc.co.uk/sport/football/64923677?at_medium=RSS&at_campaign=KARANGA Motherwell Rangers Visitors fight back in pulsating six goal thrillerRangers manager Michael Beale extends his unbeaten Scottish Premiership start to games after his side fight back to earn victory in a pulsating six goal thriller at Motherwell 2023-03-18 15:13:38
海外TECH reddit Warning https://www.reddit.com/r/NightRavenCollege/comments/11ur0x9/warning/ WarningDue to the influx of ghosts that has kidnapped my brother once I have an adequate amount of charge I will he storming in to save him If there is anyone that hasn t been kicked out of the school yet I recommend leaving at your earliest convenience Edit I have agreed to hold off for minutes to allow some people to form a plan Edit two A plan has been formed If my brother isn t saved by then I will be commencing with the original plan submitted by u mycatboo to r NightRavenCollege link comments 2023-03-18 15:13:22

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

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

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