投稿時間:2023-01-15 11:08:22 RSSフィード2023-01-15 11:00 分まとめ(9件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] 「大判焼き? 今川焼き?」呼び方を調査 地域によって違い https://www.itmedia.co.jp/business/articles/2301/15/news037.html itmedia 2023-01-15 10:34:00
Docker dockerタグが付けられた新着投稿 - Qiita GitHub Actions+Poetry+.env+pytest.ini+Dockerを使ってPytestのカバレージを表示させよう! https://qiita.com/shun198/items/99fb74483c17c4ac3eff action 2023-01-15 10:20:06
海外TECH DEV Community Build a Todo App with Next.js and AWS Amplify https://dev.to/aws-builders/build-a-todo-app-with-nextjs-and-aws-amplify-59ld Build a Todo App with Next js and AWS Amplify IntroductionIn this tutorial you ll learn how to build a serverless todo application using Next js a popular React framework for building server rendered applications and AWS Amplify a JavaScript library for cloud based app development PrerequisitesBefore getting started you will need to have the following tools installed on your development machine Node js version or higher npm comes with Node js AWS Amplify CLIYou can learn how to setup the AWS Amplify CLI here Step Set Up Next js AppTo create a new Next js app run the following command npx create next app todo appThis will create a new directory called todo app with Next js project dependencies Next navigate to the todo app directory and start the development server by running the following command cd todo appnpm run devThis will start the development server at http localhost You should see the default Next js welcome page Step Initialize AWS AmplifyNext initialize AWS Amplify in your Next js project root folder by running the following command amplify init y Step Configure Amplify APIOnce Amplify has been initialized add a backend service to the app For this tutorial we will use a GraphQL API with AWS AppSync To add the API run the following command amplify add apiFollow the prompts to create a new GraphQL API with AWS AppSync When asked for the type of API choose GraphQL This will create a schema graphql file in the amplify backend api todoapp directory Step Update Todo SchemaAfter setting up the API update the todo app GraphQL schema to specify the data types schema graphqltype Todo model id ID title String completed Boolean The code above defines a Todo type with fields for the todo title and completion status Now push the changes made to the Amplify backend by running amplify push Step Build the Todo UINow that you ve fully configured the API the next step is to build out the frontend of the application First connect Amplify to the Next js app by installing Amplify library npm install aws amplifyThen create a components folder in the root of the application which will consist of these three components CreateTodo jsx Todos jsx and TodoItem jsx In order to follow along with the styling used in this application add the Tailwind CSS amp Fontawesome CDN link to the Head tag of your pages document js lt link rel stylesheet href gt lt link rel stylesheet href gt Next update the pages index js file as shown below index jsimport Head from next head import React useState from react import Amplify API from aws amplify import awsconfig from src aws exports import as mutations from src graphql mutations import as queries from src graphql queries Amplify configure awsconfig export default function Home return lt gt lt Head gt lt title gt Create Next App lt title gt lt meta name description content Generated by create next app gt lt meta name viewport content width device width initial scale gt lt link rel icon href favicon ico gt lt Head gt lt main gt lt h gt Hello World lt h gt lt main gt lt gt Fetch Todo DataUsing Next js getStaticProps functionality let s fetch the todo data from the Amplify backend index jsexport async function getStaticProps const todoData await API graphql query queries listTodos return props todos todoData data listTodos items export default function Home todos const todoList setTodoList useState todos In the code above we used Amplify s automatically generated query listTodos imported from the src graphql queries directory to get a list of all the Todos from the backend API which is then passed as props to the main component Create TodoIn the index js file write a onCreateTodo function that will be called when a todo is created by the user index jsimport CreateTodo from components CreateTodo export default function Home todos const onCreateTodo async todo gt const newTodo title todo completed false try await API graphql query mutations createTodo variables input newTodo setTodoList list gt list newTodo console log Successfully created a todo catch err console log error err return lt CreateTodo onCreateTodo onCreateTodo gt Here the onCreateTodo function receives an input of an object with title and completed values Also this function is passed to the CreateTodo component as a propNext let s implement the CreateTodo component UI CreateTodo jsximport React useState from react const CreateTodo onCreateTodo gt const todoItem setTodoItem useState const onInputChange e gt const value e target setTodoItem value const onSubmit e gt e preventDefault onCreateTodo todoItem setTodoItem return lt gt lt form className flex justify center mt gt lt div className bg yellow px py rounded lg w gt lt h className text center mt mb text xl text white font bold gt TodoList lt h gt lt div className mt flex space x m justify center gt lt input className bg gray rounded md py px border outline none id todo name todo value todoItem placeholder Create a new Todo onChange onInputChange gt lt button className bg black text white px rounded md font semibold onClick onSubmit gt lt i className fa solid fa plus gt lt i gt lt button gt lt div gt lt div gt lt form gt lt gt export default CreateTodo Delete TodoTo delete a todo add a onDeleteTodo function to the index js file that deletes a todo based on its id field and then pass it as a prop to the Todos jsx component index jsimport Todo from components Todos export default function Home todos const onDeleteTodo async id gt try await API graphql query mutations deleteTodo variables input id const filterTodo todoList filter todo gt todo id id setTodoList filterTodo console log Successfully deleted a todo catch err console log err return lt Todo todoList todoList onDeleteTodo onDeleteTodo gt Note that the onDeleteTodo function will be implemented on a delete button for each todo items later on in the tutorial Display Todos ComponentNext we will implement the UI for displaying the list of todos Update the Todos jsx with the following content Todos jsximport React from react import TodoItem from TodoItem const Todo todoList onDeleteTodo gt return lt gt lt div className h screen gt lt div gt todoList map todo gt lt TodoItem key todo id todo todo onDeleteTodo onDeleteTodo gt lt div gt lt div gt lt gt export default Todo From the code above we iterated through the array of todos which will then display each todo as a TodoItem component Update TodoIn the TodoItem jsx component let s create a onUpdateTodo function that uses the API s updateTodo mutation imported from the src graphql mutations directory to allow users mark a todo as completed or not TodoItem jsximport React useState from react import API from aws amplify import as mutations from src graphql mutations const onUpdateTodo async event gt setIsCompleted event target checked const input id todo id completed event target checked try await API graphql query mutations updateTodo variables input input console log Todo successfully updated catch err console log error err Display Todo ItemsLet s update the TodoItem component so we can display each todo item with a working checkbox and delete icon TodoItem jsxconst TodoItem todo onDeleteTodo gt const isCompleted setIsCompleted useState todo completed return lt gt lt div className flex justify center gt lt div className relative justify center mt w gt lt div className bg white px pt pb rounded md text gray shadow lg gt lt div key todo id style textDecoration isCompleted line through undefined gt lt input type checkbox checked isCompleted onChange OnUpdateTodo className h w gt lt span className pl gt todo title lt span gt lt div gt lt div gt lt div className absolute flex top right p space x gt lt span className text red cursor pointer onClick gt onDeleteTodo todo id gt lt i className fa solid fa trash gt lt i gt lt span gt lt div gt lt div gt lt div gt lt gt export default TodoItem Step Deploy the AppNow that we have our todo app implemented we can deploy it to the cloud To deploy the app run the following command amplify add hostingThen run amplify publishThis will build the app and deploy it to AWS When the deployment is complete you will see a URL where you can access the app ConclusionIn this tutorial we have successfully built a serverless todo app using AWS Amplify and Next js We defined a GraphQL API using AWS AppSync Finally we deployed the app to the cloud using AWS Amplify I hope you have found this tutorial helpful You can find the full source code in this Github repo and the demo here 2023-01-15 01:41:42
ニュース BBC News - Home Why Michigan is trying to shut down Canada's Enbridge Line 5 pipeline https://www.bbc.co.uk/news/world-us-canada-63879493?at_medium=RSS&at_campaign=KARANGA pipelinean 2023-01-15 01:14:34
ニュース BBC News - Home NFL play-offs: Brock Purdy leads San Francisco 49ers to wildcard win over Seattle Seahawks https://www.bbc.co.uk/sport/american-football/64279486?at_medium=RSS&at_campaign=KARANGA NFL play offs Brock Purdy leads San Francisco ers to wildcard win over Seattle SeahawksBrock Purdy continues his remarkable NFL start by leading the San Francisco ers to a win in the opening game of this season s play offs 2023-01-15 01:27:30
ビジネス プレジデントオンライン 実は愛知、静岡ではない…NHK大河『どうする家康』で漁夫の利を得る家康、信長、秀吉の墓がある都市 - "三英傑"の墓所巡りでわかった意外な歴史的事実 https://president.jp/articles/-/65402 歴史的事実 2023-01-15 11:00:00
ビジネス プレジデントオンライン 長生きしたければ「冬場の暖房代」をケチってはいけない…脳科学者が指摘する「脳がボケる部屋」の条件【2022下半期BEST5】 - 脳がフル稼働する「湿度」がある https://president.jp/articles/-/65399 脳科学者 2023-01-15 11:00:00
ビジネス プレジデントオンライン 浮気、暴力、セックスレス…夫婦の難題を解決する名カウンセラーが必ず「心理テスト」を受けさせる理由 - 突然ブチぎれる夫を「俺ってヤバい」と認めさせる秘策 https://president.jp/articles/-/65397 心理テスト 2023-01-15 11:00:00
ビジネス プレジデントオンライン 浮気、暴力、セックスレス…夫婦の難題を解決する名カウンセラーが必ず「心理テスト」を受けさせる理由 - 突然ブチぎれる夫を「俺ってヤバい」と認めさせる秘策 https://president.jp/articles/-/65336 心理テスト 2023-01-15 11:00:00

コメント

このブログの人気の投稿

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