投稿時間:2023-03-22 11:33:15 RSSフィード2023-03-22 11:00 分まとめ(35件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… iTunes Storeの「今週の映画」、今週は「イン・ザ・ハイツ」(レンタル102円) https://taisy0.com/2023/03/22/169840.html apple 2023-03-22 01:01:14
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] 首都圏の「借りて&買って」住んだ街の住みここち 2年連続トップの街は? https://www.itmedia.co.jp/business/articles/2303/22/news041.html itmedia 2023-03-22 10:30:00
IT ITmedia 総合記事一覧 [ITmedia Mobile] Xiaomiからハローキティとコラボしたスマホが登場 背面の“特殊な仕上げ”に注目 https://www.itmedia.co.jp/mobile/articles/2303/22/news091.html itmediamobilexiaomi 2023-03-22 10:06:00
TECH Techable(テッカブル) NTTコノキュー、MR活用の遠隔作業支援ソリューション提供。手順書のデジタル表示が可能 https://techable.jp/archives/200819 realsu 2023-03-22 01:00:22
AWS AWS Japan Blog Amazon S3’s の 17 歳の誕生日を AWS Pi Day 2023 でお祝いしましょう https://aws.amazon.com/jp/blogs/news/celebrate-amazon-s3s-17th-birthday-at-aws-pi-day-2023/ twitc 2023-03-22 01:39:38
python Pythonタグが付けられた新着投稿 - Qiita AzureMachineLearningを触ってみた https://qiita.com/fsd_yoshikawa/items/ec1a57302a4ab11b5e4f azure 2023-03-22 10:47:33
python Pythonタグが付けられた新着投稿 - Qiita Raspberry Pi Pico上でMicroPythonを使用し、外部ライブラリをinstall https://qiita.com/rikuto125/items/25542d890e219e9b447e installraspberrypipico 2023-03-22 10:36:38
js JavaScriptタグが付けられた新着投稿 - Qiita [JavaScript/TypeScript]base64形式の画像データをFile型に変換したい https://qiita.com/i_110/items/a3be68838b0808345b26 javascript 2023-03-22 11:00:00
js JavaScriptタグが付けられた新着投稿 - Qiita 【パブリッシャー】丸見えトークンへの対応を試みる https://qiita.com/Miki_Yokohata/items/77d0729730bd071698c3 sharperlight 2023-03-22 10:47:11
Ruby Rubyタグが付けられた新着投稿 - Qiita Rails7でActionController::ParametersをMarshal.dumpしようとすると TypeError (can't dump IO) となる https://qiita.com/nu_368/items/b99967f93fe19c8d8dc3 actioncontroller 2023-03-22 10:09:51
AWS AWSタグが付けられた新着投稿 - Qiita AWS Parallel ClusterとAmazon FSx for NetApp ONTAPで創るクラウドHPCクラスタ 第3回 https://qiita.com/Yoshinori_Tsukioka/items/227eed175d4985646759 amazonfsxfornetappontap 2023-03-22 10:09:01
AWS AWSタグが付けられた新着投稿 - Qiita AWS Parallel ClusterとAmazon FSx for NetApp ONTAPで創るクラウドHPCクラスタ 第2回 https://qiita.com/Yoshinori_Tsukioka/items/58f008bb426de850bead amazonfsxfornetappontap 2023-03-22 10:07:29
AWS AWSタグが付けられた新着投稿 - Qiita AWS Parallel ClusterとAmazon FSx for NetApp ONTAPで創るクラウドHPCクラスタ 第1回 https://qiita.com/Yoshinori_Tsukioka/items/2db619c7fb30fdb7bd21 amazonfsxfornetappontap 2023-03-22 10:06:09
Docker dockerタグが付けられた新着投稿 - Qiita dockerコマンド https://qiita.com/nakanaka444/items/f75fcae8f89696b9ec6e dockercomposeupbuilddoc 2023-03-22 10:04:17
Azure Azureタグが付けられた新着投稿 - Qiita AzureMachineLearningを触ってみた https://qiita.com/fsd_yoshikawa/items/ec1a57302a4ab11b5e4f azure 2023-03-22 10:47:33
Ruby Railsタグが付けられた新着投稿 - Qiita Rails7でActionController::ParametersをMarshal.dumpしようとすると TypeError (can't dump IO) となる https://qiita.com/nu_368/items/b99967f93fe19c8d8dc3 actioncontroller 2023-03-22 10:09:51
技術ブログ Developers.IO EKS でノードグループ削除が「削除失敗」になったときの対処方法 https://dev.classmethod.jp/articles/tsnote-eks-node-group-deletion-failed/ 確認 2023-03-22 01:42:58
技術ブログ Developers.IO ChatGPTにCSVのサンプルデータ作ってもらう https://dev.classmethod.jp/articles/chatgpt_make_sampledata/ chatgpt 2023-03-22 01:13:06
技術ブログ Yahoo! JAPAN Tech Blog ABテストが難しい場合の施策効果の評価・推定方法 https://techblog.yahoo.co.jp/entry/2023032230418127/?cpt_n=BlogFeed&cpt_m=lnk&cpt_s=rss 適用 2023-03-22 11:00:00
海外TECH DEV Community 100 Crucial Keyboard Shortcuts for VS Code Users. https://dev.to/devland/100-crucial-keyboard-shortcuts-for-vs-code-users-4474 Crucial Keyboard Shortcuts for VS Code Users In the world of software development time is a precious commodity With deadlines looming and projects piling up anything that can save time and improve productivity is crucial That s where Visual Studio Code VS Code comes in As one of the most popular code editors available today VS Code offers a plethora of powerful features and tools that can significantly streamline the coding process One of the most valuable features of VS Code is its extensive set of keyboard shortcuts that allow developers to perform common tasks quickly and efficiently In this article we will be highlighting the most important VS Code shortcuts that every VS Code user should know to become more efficient and productive in their work Shortcuts for searching and navigating through source codeWhen working on a project with a large number of classes locating members of a class can be a daunting and time consuming task However with the right tools this process can be significantly streamlined In Visual Studio there are several keyboard shortcuts that allow for quick and easy navigation and search operations Let s take a look at these shortcuts that can help us perform quick searches and navigation Ctrl Q Displays Visual Studio SearchCtrl T Displays the Go To All toolCtrl Navigates backward between opened documents in the current sessionCtrl Shift Navigates forward between opened documents in the current sessionF Navigates to a class definitionAlt F Allows you to view and edit the code of a class in a pop up window from the code file you are writing Ctrl F Navigates to the implementation of a member in a classCtrl Shift F Moves to the next error line when the error list window is open and more than one error is listedF Navigates forward in the list of results of the current windowShift F Navigates backward in the list of results of the current window Shortcuts for editing and refactoringIn this part we will focus on the commands that enable direct changes to the source code These commands are essential for carrying out common operations such as renaming members commenting on lines of code and moving lines up and down Alt Enter Displays quick actionsCtrl K Ctrl I Obtains information about a member of a classCtrl K Ctrl C Comments multiple selected lines in the source codeCtrl K Ctrl U Uncomments multiple selected lines in the source code Ctrl Shift L Deletes selected linesCtrl Shift V Displays and allows pasting the contents from the buffer ring it refers to the history of elements that have been previously copied Ctrl F Finds a specific text in the codeCtrl A Selects all the lines in the current fileCtrl S Saves the pending changes in the current fileCtrl Shift S Saves the pending changes in all the opened files Ctrl Shift Zooms into the current fileCtrl Shift Zooms out from the current fileCtrl Up Moves selected lines up in a code fileCtrl Down Moves selected lines down in a code fileCtrl K Ctrl D Applies the style rules to the entire document Ctrl K Ctrl F Applies the style rules only in the selected lines in the documentCtrl K Ctrl S Used to encapsulate the code between common clauses such as cycles while for and so on control statements if switch and so on or code regions region Ctrl R Renames a memberCtrl R Ctrl E Creates a property for a field of a class Ctrl R Ctrl G Removes unused using statements in a class and sorts them alphabeticallyCtrl R Ctrl M Creates a method from the selected codeCtrl X Cut line empty selection Ctrl Toggle line commentCtrl Home Go to beginning of file Shortcuts for debugging and testingIn Visual Studio debugging and executing code are frequent tasks that we do As such it is crucial to familiarize ourselves with the keyboard shortcuts that can facilitate these operations and enable us to carry them out quickly and efficiently Knowing these shortcuts can save valuable time and boost productivity So let s take a look at the essential keyboard shortcuts that will help us execute code and debug with ease F Starts the application in debug modeCtrl F Starts the application without debug modeShift F Stops the application when it s runningCtrl Shift F Stops the application execution rebuilds the project and creates a new debugging sessionF Places or removes a breakpointF Skips the execution of code when debuggingF Debugs source code line by lineShift F Steps out of the execution of the methodCtrl R Ctrl A Starts unit test execution in debug modeCtrl R A Starts unit test execution without debug mode The most common shortcuts for use in the IDEWhen working in VS Code it s not uncommon to accidentally close essential windows such as the Solution Explorer or Properties window and struggle to locate the option to reopen them Therefore being familiar with the keyboard shortcuts for frequently used windows and panels can save significant time and effort Let s explore the essential keyboard shortcuts that will help us move around the Visual Studio IDE with ease Ctrl S If we have a file open this shortcut allows us to quickly select it in the Solution Explorer window Ctrl Alt L Opens the Solution Explorer windowCtrl Alt O Opens the Output window Ctrl E Opens the Error List windowCtrl Ctrl M Opens the Team Explorer window Ctrl Alt B Opens the Breakpoints window F Opens the Properties window Alt F Allows you to scroll back between windows on the panels that are open Shift Alt F Allows you to scroll forward between windows on the panels that are open Shift Esc Allows you to close the current tool windowCtrl Alt Pg Up Allows scrolling up between open documents even when it is not the same session Ctrl Alt Pg Dn Allows scrolling down between open documents even when it is not the same session Ctrl Tab Displays a special window with the open documents and selects the most recent one Ctrl Shift Tab Displays a special window with the open documents and selects the least recent one Shift Alt Enter Allows you to place the Visual Studio environment at full screen allowing you to concentrate on the current document Use the same shortcut to get out of full screen modeCtrl K K Creates a bookmark in the line where we are positioned If there is already a bookmark on that line it will be deleted Ctrl K N Allows you to scroll forward through the different bookmarks that are part of a project Ctrl K P Allows you to scroll backward through the different bookmarks that are part of a project Ctrl Shift P F Show Command PaletteCtrl P Quick Open Go to File…Ctrl Shift N New window instanceCtrl Shift W Close window instanceCtrl User SettingsCtrl Show integrated terminalCtrl Shift Create a new terminal Shortcuts for file managementOne of the key features of VS Code is its file management capabilities which allow developers to efficiently create open edit save and organize files and folders VS Code provides a range of keyboard shortcuts that enable developers to manage their files and folders quickly and easily These shortcuts include creating new files and folders opening and closing files switching between open files and accessing the Explorer panel to view the file and folder structure of the project By using these shortcuts you can save time avoid errors and stay organized while working on their projects Here is a list of some of the most commonly used VS Code shortcuts for file management Ctrl N Create a new fileCtrl O Open a fileCtrl S Save a fileCtrl Shift S Save all open filesCtrl P Open the Quick Open dialog to quickly search and open a fileCtrl Tab Switch between open filesCtrl W Close the current fileCtrl Shift T Reopen the last closed fileCtrl Shift N Create a new folderCtrl Shift E Show hide the Explorer panel which displays the file and folder structure of your projectCtrl K Enter Keep preview mode editor open SummaryThis article has provided a comprehensive list of essential shortcuts that every VS Code user should know These shortcuts cover various areas such as file management editing code navigating the editor and accessing VS Code features By incorporating these shortcuts into your daily routine you can save time and effort reduce errors and become more productive With continued practice and familiarity with these shortcuts you can elevate your coding skills to new heights and take full advantage of what VS Code has to offer THANK YOU FOR READING I hope you found this little article helpful Please share it with your friends and colleagues Sharing is caring Connect with me on Twitter or LinkedIn to read more about JavaScript React Node js and more… Want to work together Contact me on Upwork 2023-03-22 01:35:42
海外TECH DEV Community 5 Top Reasons to Use GitHub Actions for Your Next Project https://dev.to/n3wt0n/5-top-reasons-to-use-github-actions-for-your-next-project-cga Top Reasons to Use GitHub Actions for Your Next ProjectA lot of people have been asking me on Twitter Discord Facebook etc whether they should be using GitHub Actions and why choosing it over other services So I ve decided to put together of the most important reasons why I think GitHub Actions is a great service VideoAs usual if you are a visual learner or simply prefer to watch and listen instead of reading here you have the video with the whole explanation Link to the video If you rather prefer reading well let s just continue AutomationAnyway why use GitHub Actions Well first reason is Automation GitHub Actions can automate your workflow allowing you to build test and deploy your code right from GitHub This can save you a lot of time and effort For example you can use GitHub Actions to automatically build and test your code every time you push a commit to GitHub This ensures that your code is always up to date and working as expected But it doesn t stop here As you may have heard me saying already you can also use GitHub Actions to automate other tasks such as sending notifications running scripts managing pull requests and issues and much more I have a whole video about automating stuff with Actions you have the link up here and in the video description CustomizationSecond reason to use the service is Customization GitHub Actions are highly customizable You can create your own actions or use actions from the GitHub Marketplace to build workflows that meet your specific needs For example you can use a pre built action to deploy your code to a specific cloud provider Or you can create your own action to run a custom test suite You can also use environment variables and secrets to customize your workflows even further If you can think about it you can do it There is no limit with GitHub Actions Oh btw let me know in the comments if you want me to cover the creation of custom actions in a future article video IntegrationAnother reason to use GitHub Actions the third one is Integration GitHub Actions integrates seamlessly with other GitHub features such as pull requests and issues This makes it easy to manage your entire workflow in one place For example you can use GitHub Actions to automatically build and test your code whenever a pull request is opened This ensures that your code is always tested before it s merged into your main branch You can also use GitHub Actions to automatically close issues or assign them to specific team members Furthermore Actions integrate with the major cloud providers including Azure AWS and GCP and most of the common DevOps and work management tools like Jira Service Now Slack etc and you can use it even if your code is not in GitHub like if you are using for example GitLab Azure DevOps Jenkins etc CommunityFourth reason to use GitHub Action The Community GitHub Actions has a large and active community And this is a double advantage You can find many pre built actions in the GitHub Marketplace and you can also share your own actions with the community This makes it easy to find and use actions that meet your specific needs You can also contribute to the community by creating your own actions or improving existing ones As I ve mentioned there is a second advantage to the large community behind GitHub Actions the support You can literally find thousands and thousands of people who have either experienced already your pain points and challenges and so you have the solutions arleady ready or you can ask in forums like Stack Overflow or GitHub s own portal “GitHub Community and have the answers to your questions in literally minutes CostAnd if you need one more reason to use GitHub Actions the fifth and last one of this video that would be Cost Or better lack thereof GitHub Actions in fact is free for public repositories and you get free minutes of build time per month for private repositories This makes it an affordable option for developers of all sizes If you need more build time you can purchase additional minutes at a reasonable price You can also use self hosted runners to run your workflows on your own infrastructure ConclusionsLet me know in the comments if you have other important reasons why you think someone should use GitHub Actions and if you want to know more about the service check out my complete and a half our GitHub Actions course Like share and follow me for more content YouTube Buy me a coffeePatreonNewsletterCoderDave io WebsiteMerchFacebook page‍GitHubTwitterLinkedInPodcast 2023-03-22 01:24:25
海外TECH DEV Community Setting up Node.js Email Server with Nodemailer and Mailtrap https://dev.to/desmondsanctity/setting-up-nodejs-email-server-with-nodemailer-and-mailtrap-404 Setting up Node js Email Server with Nodemailer and Mailtrap IntroductionThe email service is one of the services common to every software application Emails are used to communicate pieces of information mostly about downtime updates and verification of activities by the user in a software application In this tutorial we will be demonstrating how to set up an email server in a Node js application using Nodemailer and Mailtrap First of all let us learn the basics NodemailerNodemailer is a module for Node js applications that allows easy as cake email sending The project started back in when there was no better option for sending email messages today it is still the solution most Node js users turn to by default Underneath the hood Nodemailer uses the Node js core module net to create a connection to the SMTP server specified in the transport object Once a connection is established Nodemailer uses the SMTP protocol to send email messages by sending various commands and responses over the connection Here s a simplified example of how Nodemailer sends an email message Create a transport object that defines the SMTP server authentication credentials and other options Create a message object that defines the email message including the sender recipient subject and body Use the transporter sendMail method to send the message passing in the message object and a callback function to handle any errors or responses Nodemailer uses the transport object to establish a connection to the SMTP server and send the message using the SMTP protocol If the message is sent successfully Nodemailer returns a response object containing information about the message like the message ID and the response from the SMTP server Overall Nodemailer provides a simple and powerful interface for sending email messages in Node js taking away the complexities of the SMTP protocol and allowing developers to focus on the content and delivery of their messages MailtrapMailtrap is a service that provides a mock SMTP server for testing and development purposes It allows developers to test their email sending functionality without actually sending emails to real recipients Mailtrap works by creating a temporary SMTP server that is accessible through a unique hostname and port number When an email is sent to the Mailtrap server it is intercepted and stored in your Mailtrap inbox instead of being sent to the intended recipient Mailtrap also provides a web interface that allows you to view and manage your test email messages as well as features like email forwarding and spam testing Here are the following steps to enable Mailtrap to work with Nodemailer Sign up for a Mailtrap account and create a new inbox Retrieve your SMTP credentials from the Mailtrap inbox settings Configure Nodemailer to use the Mailtrap SMTP server by creating a transport object with the SMTP settings from Mailtrap Use the transporter sendMail method to send email messages just like you would with any other SMTP server Check your Mailtrap inbox to see the test email message The message will be displayed in the inbox with its headers and content allowing you to verify that it was sent correctly Overall Mailtrap is a useful tool for testing and debugging email functionality in a safe and controlled environment By using Mailtrap with Nodemailer developers can test their email sending functionality without the risk of accidentally sending test emails to real recipients or getting blocked by spam filters Setting up the Email ServerNow that we ve had the basics out of the way let us delve into a more interesting part we will be setting up the email server using Node js The process follows this form Creating Mailtrap AccountGo to the Mailtrap website and sign up When the sign up is completed you will see a screen like the one below Click on Email Testing to get your secret credentials Select Nodemailer as an integration option and you will get a screen like the one below At this point you d have to save the keys it would be needed to set up the application later Setup Node js ProjectTo set up our Node js server we need to create a project folder that will contain our application For this tutorial we will call the folder node email server To begin we will run the following commands from our terminal cd desktop amp amp mkdir node email server cd node email server code this is to open the folder in our code editor VSCode In the root folder run the following command to install the packages we will be using npm install nodemon nodemailer dotenv cors express mailgenNodemonーautomatically restarts the node application when file changes in the directory are detected Corsーfor providing an Express middleware that can be used to enable CORS with various options ExpressーNode js web application framework that provides a robust set of features for web and mobile applications MailgenーNode js package that generates clean responsive HTML e mails for sending transactional mail Create a env file in the root folderーthis is where we will store the Mailtrap keys we generated earlier EMAIL lt sender s email address gt USER lt mailtrap user key gt PASSWORD lt mailtrap password gt We will proceed to create the server file in our case it is the index js file Add the following code to the server file import express from express import cors from cors import dotenv from dotenv import nodemailer from nodemailer import Mailgen from mailgen dotenv config configure our app to use env variables const app express middlewares app use express json app use cors app disable x powered by less hackers know about our stack const port process env PORT HTTP GET Request app get req res gt res status json Health Check PASS create reusable transporter object using the default SMTP transport const transporter nodemailer createTransport host smtp mailtrap io port auth user process env USER generated mailtrap user pass process env PASSWORD generated mailtrap password generate email body using Mailgen const MailGenerator new Mailgen theme default product name Test Email link define a route for sending emails app post send email req res gt get the recipient s email address name and message from the request body const to name message req body body of the email const email body name name intro message Welcome to Test Mail We re very excited to have you on board outro Need help or have questions Just reply to this email we d love to help const emailBody MailGenerator generate email send mail with defined transport object const mailOptions from process env EMAIL to to subject Test Email html emailBody transporter sendMail mailOptions error info gt if error console log error res status send Error sending email else console log Email sent info response res send Email sent successfully start the server app listen port gt console log Server started on port port Firstly we imported the packages we will be needing and created an app instance using express We defined our middleware and port The interesting parts are The email transport instance was created with nodemailer and using the SMTP details that mailtrap provided usThe function MailGenerator which we used to generate clean responsive HTML e mails The route which houses those logics we need for sending email requests to the server whenever the send email endpoint is called Finally we started the server and let the app listen to the defined port which we will use to access and test our email API Testing our Email ServerThis is my favourite part of the whole process testing our endpoint to see if our application actually works For this tutorial we will be using Postman a HTTP client used to test debug or document API You can set up Postman as a desktop application or use it as a web app without installing it on your local machine Check here for more details on how to set it up with any option you want Making a requestOur app is running on http localhost so our endpoint is exposed to this url http localhost send email We will send a POST request to the endpoint with three parameters in the body of the request which are to the email address of the recipient of the mail name the name of the recipient and message which is optional if we do not want to overwrite the default message in our application Here is what our Postman request and response will look like If we check our Mailtrap account we will see the mail we just sent and viola our app works as expected Here is what mine looks like ConclusionWe have learnt how to use Nodemailer and Mailtrap to set up a Node js email server and also how these technologies work behind the scene The code repository for this project can be found here Note that Nodemailer works with other SMTP providers like Gmail Hotmail MailGun SendGrid SendinBlue etc The list of supported services can be found here too If you enjoyed the article feel free to leave a comment give it a shout out and share it with others Bueno 2023-03-22 01:15:27
海外TECH DEV Community Embedding Data Into React/JSX Elements https://dev.to/bytebodger/embedding-data-into-reactjsx-elements-3jcp Embedding Data Into React JSX ElementsWhat I m about to show you is really pretty basic So Code Gurus out there can feel free to breeze on by this article But I ve rarely seen this technique used even in established codebases crafted by senior devs So I decided to write this up This technique is designed to extract bits of data that have been embedded into a JSX or plain ol HTML element Why would you need to do this Well I m glad you asked The ScenarioLet s look at a really basic function const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td key cell rowIndex cellIndex gt paintIndex lt td gt This function simply builds a particular row of table cells It s used in my app to build a color map It generates a giant grid table that shows me for every block in the grid which one of my paints most closely matches that particular block Once this feature was built I decided that I wanted to add an onClick event to each cell The idea is that when you click on any given cell it then highlights every cell in the grid that contains the same color as the one you ve just clicked upon Whenever you click on a cell the onClick event handler needs to understand which color you ve chosen In other words you need to pass the color into the onClick event handler Over and over again I see code that looks like this to accomplish that kinda functionality const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td key cell rowIndex cellIndex onClick paintIndex gt handleCellClick paintIndex gt paintIndex lt td gt The code above isn t wrong It will pass the paintIndex to the event handler But it isn t really optimal The inefficiency that arises is that for every single table cell we re creating a brand new function definition That s what paintIndex gt handleCellClick paintIndex does It spins up an entirely new function If you have a large table that s a lotta function definitions And those functions need to be redefined not just on the component s initial render but whenever this component is re invoked Ideally you d have a static function definition for the event handler That would look something like this const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td key cell rowIndex cellIndex onClick handleCellClick gt paintIndex lt td gt In the above code the handleCellClick has already been defined outside this function So React doesn t need to rebuild a brand new function definition every single time that we render a table cell Unfortunately this doesn t entirely work either Because now every time the user clicks on a table cell the event handler will have no idea which particular cell was clicked So it won t know which paintIndex to highlight Again the way I normally see this implemented even in well built codebases is to use the paintIndex gt handleCellClick paintIndex approach But as I ve already pointed out this is inefficient So let s look at a couple ways to remedy this Wrapper ComponentsOne approach is to create a wrapper component for my table cells That would look like this const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt MyTableCell key cell rowIndex cellIndex paintIndex paintIndex gt paintIndex lt MyTableCell gt In this scenario we re no longer using the base HTML attribute of lt td gt Instead there s a custom component that will accept paintIndex as a prop and then presumably use that prop to build the event handler MyTableCell would look something like this const MyTableCell paintIndex gt const handleCellClick gt event handler logic return lt td onClick handleCellClick gt paintIndex lt td gt Using this approach we don t have to pass the paintIndex value into the handleCellClick event handler because we can simply reference it from the prop There s much to like in this solution because it s consistent with an idiomatic approach to React Ideally you d even memoize the MyTableCell component so it doesn t get remounted and re rendered every time we build a table cell that uses the same paint color However this approach can also feel a bit onerous because we re cranking out another component purely for the sake of making that one onClick event more efficient Also if the handleCellClick event handler needs to do other logic that impacts that state in the calling component the resulting code can get a bit heavy Sometimes you want the logic for that event handler to be handled right inside the calling component Luckily there are other ways to do this HTML AttributesHTML affords us a lot of freedom to stuff data where it s needed For example you could use the longdesc attribute to embed the paintIndex right into the HTML element itself Unfortunately longdesc is only allowed in lt frame gt lt iframe gt and lt img gt elements Granted browsers are tremendously forgiving about the usage of HTML attributes So if you were to start putting longdesc attributes on all sorts of illegal HTML elements it really won t break anything The browser will basically just ignore the non idiomatic attributes In fact you can even add your own custom attributes to HTML elements Nevertheless it s usually good practice to avoid stuffing a buncha non allowed or completely custom attributes into your HTML elements But we have more options More standard options Near Universal HTML AttributesIf you wanna find an attribute that you can put on pretty much any element the first things is to look at the attributes that are allowed in almost any elements They are as follows idclassstyletitledirlang xml langThe nice thing about these attributes is that you can pretty much use them anywhere within the body of your HTML on pretty much any HTML element and you don t have to worry about whether they re allowed You can for example put a title attribute on a lt div gt or a dir attribute on a lt td gt It s all acceptable by HTML standards that is So if you wanted to use one of these attributes to pass data into an event handler what would be the best choice titleFirst of all as tempting as it may be to use something like title I would not recommend this title is used by screen readers and you re gonna jack up the accessibility of your site if you stuff a bunch of programmatic data into that attribute data that should not be read by a screen reader dir lang xml langSimilarly you should avoid appropriating the dir lang or xml lang attributes Messing with these attributes could jack up the utility of the site for international users i e those who are using your site with a different language So please leave those alone as well styleAlso you could try to cram custom data into a style attribute But IMHO that s gonna come out looking convoluted In theory you could define a custom style property like this lt td style paintIndex paintIndex gt Then you could try to read this made up style property on the element when it s captured in the event handler But I don t recommend such an approach Not at all First if you have any legitimate style properties set on the element you re gonna end up with a mishmash of real and made up properties Second there s no reason to embed data in such a verbose format You can do it much cleaner with the other options at our disposal idThe id attribute can be a great place to embed data Here s what that would look like const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td id paintIndex key cell rowIndex cellIndex onClick handleCellClick gt paintIndex lt td gt Here we re using the paintIndex as the id Why would we do this Because then we can create an event handler that looks like this const handleCellClick event gt uiState toggleHighlightedColor event target id This works because the synthetic event that s passed to the event handler will have the id of the clicked element embedded within it This allows us to use a generic event handler on each table cell while still allowing the event handler to understand exactly which paintIndex was clicked upon This can still have some drawbacks First of all ids are supposed to be unique In the example above a given paintIndex may be present in a single table cell or in hundreds of them And if we simply use the paintIndex value as the id we ll end up with many table cells that have identical id values To be clear having duplicate ids won t break your HTML display But in some scenarios it can break your JavaScript logic Thankfully we can fix that too Notice that our table cells have key values And keys must be unique In this scenario I addressed that problem by using the row cell counts to build the key Because no two cells will have the same combination of row cell numbers We can add the same format to our id That looks like this const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td id cell rowIndex cellIndex paintIndex key cell rowIndex cellIndex onClick handleCellClick gt paintIndex lt td gt Now there will never be a duplicate id on any of our cells But we still have the paintIndex value embedded into that id So how do we extract the value in our event handler That looks like this const handleCellClick event gt const paintIndex event target id split pop uiState toggleHighlightedColor paintIndex Since we wrote this code and since we determined the naming convention for the id we also know that the paintIndex value will be the last value in a string of values that are delimited by If we split that string and then pop the last value off the end of it we know that we re getting the paintIndex value classclass is also a great place to embed data even if it doesn t map to any CSS class that s available to the script If you re familiar with jQuery UI you ve probably seen many instances where class is used as a type of switch that doesn t actually drive CSS styles Instead it tells the JavaScript code what to do Of course in JSX we don t use class We use className So that solution would look like this const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td className paintIndex key cell rowIndex cellIndex onClick handleCellClick gt paintIndex lt td gt And the event handler looks like this const handleCellClick event gt uiState toggleHighlightedColor event target className Just as we previously grabbed paintIndex from the event object s id field we re now grabbing it from className How would this work if you also had real CSS classes in the className property That would look like this const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td className cell paintIndex key cell rowIndex cellIndex onClick handleCellClick gt paintIndex lt td gt And the event handler would look like this const handleCellClick event gt const paintIndex event target className split pop uiState toggleHighlightedColor paintIndex The cell class on the lt td gt is a real class meaning that it maps to predefined CSS properties But we also embedded the paintIndex value into the className property and we extracted it by splitting the string on empty spaces To be fair this approach may feel a bit brittle Because it depends upon the paintIndex value being the last value in the space delimited className string If another developer came in and added another CSS class to the end of the className field like this const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td className cell paintIndex anotherCSSClass key cell rowIndex cellIndex onClick handleCellClick gt paintIndex lt td gt The logic would break Because the event handler would grab anotherCSSClass off the end of the string and try to treat it like it s the paintIndex If you d like to make it a bit more robust you can change the logic to something like this const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td className cell paintIndex paintIndex anotherCSSClass key cell rowIndex cellIndex onClick handleCellClick gt paintIndex lt td gt And then update the event handler like this const handleCellClick event gt const paintIndex event target className split find className gt className includes paintIndex split pop uiState toggleHighlightedColor paintIndex By doing it this way the value that s extracted for paintIndex isn t dependent upon being the last item in the space delimited string It can exist anywhere inside the className property as long as it s prepended with paintIndex Why Should You Care To be frank in small apps having something like this isn t exactly a federal crime const getTableCells cells rgbModel rowIndex gt return cells map cell cellIndex gt const paintIndex colors findIndex color gt color name cell name return lt td key cell rowIndex cellIndex onClick paintIndex gt handleCellClick paintIndex gt paintIndex lt td gt The performance hit you incur by defining a new function definition inside the onClick property is minimal In some cases trying to fix it could be understandably defined as a micro optimization But I do believe it s a solid practice to to get in the habit of avoiding these whenever possible When the event handler doesn t need to have information passed into it from the clicked element it s a no brainer to keep arrow functions out of your event properties But when it does require element specific info too often I see people blindly fall back on the easy method of dropping arrow functions into their properties But there are many ways to avoid this and they require little additional effort 2023-03-22 01:03:10
Apple AppleInsider - Frontpage News Baseus Bowie M2 Plus review: Small wireless earbuds, mighty sounds https://appleinsider.com/articles/23/03/22/baseus-bowie-m2-plus-review-small-wireless-earbuds-mighty-sounds?utm_medium=rss Baseus Bowie M Plus review Small wireless earbuds mighty soundsThe Baseus Bowie M Plus wireless earbuds can be handy if you want to listen to music and block out unwanted noise Besides being noise canceling they are app enabled to create your unique sound profile Baseus Bowie M Plus wireless earbuds reviewThe Bowie M Plus earbuds are a much cheaper alternative to Apple s AirPods Pro so don t expect these to provide the same performance Yet these earbuds deliver clear audio and powerful sounds and can be used when you don t want to risk damaging your AirPods Pro when exercising or traveling Read more 2023-03-22 01:43:32
ニュース BBC News - Home Chris Mason: 'Box set Boris Johnson' is pure political theatre https://www.bbc.co.uk/news/uk-politics-65034673?at_medium=RSS&at_campaign=KARANGA editor 2023-03-22 01:44:54
GCP Google Cloud Platform Japan 公式ブログ 日立製作所:品質管理に Visual Inspection AI を利用した画像認識を導入し PoC で不具合判別率 100% を達成 https://cloud.google.com/blog/ja/topics/customers/hitachi-using-visual-inspection-ai-for-quality-control/ 日立製作所品質管理にVisualInspectionAIを利用した画像認識を導入しPoCで不具合判別率を達成様々な分野で先進的な製品やサービスを展開している総合電機メーカーの株式会社日立製作所以下、日立製作所。 2023-03-22 01:10:00
ニュース Newsweek ミツバチを感染症から守れ!新型ワクチン開発、米バイオ企業の挑戦 https://www.newsweekjapan.jp/stories/business/2023/03/post-101157.php この方法は女王蜂に不活性化されたAFB菌を投与することで、蜂の巣で孵化した幼虫の感染への耐性を高める効果がある。 2023-03-22 10:50:00
ニュース Newsweek ご利用限度額はCO2換算で──日本でも急激に注目を集めるスウェーデン発「ドコノミー」とは? https://www.newsweekjapan.jp/stories/business/2023/03/post-101147.php ドコノミーと契約した初の日本企業となった。 2023-03-22 10:40:52
マーケティング MarkeZine 「売り上げに直結するマーケティング」を実現するには?効果的な成果管理をするための3つのポイント http://markezine.jp/article/detail/41585 売り上げ 2023-03-22 10:30:00
IT 週刊アスキー ダイソン、日本限定「さくらロゼ」ヘアケア製品発表 - 限定イベントも開催 https://weekly.ascii.jp/elem/000/004/129/4129423/ 期間限定 2023-03-22 10:45:00
マーケティング AdverTimes オダギリジョー&山﨑天の父娘12年を描く 相鉄・東急直通線開業ムービー https://www.advertimes.com/20230322/article414277/ youtube 2023-03-22 02:00:15
マーケティング AdverTimes 『ONE PIECE』105巻発売、新章への期待を高めた発売記念ムービー https://www.advertimes.com/20230322/article414316/ onepiece 2023-03-22 01:49:11
マーケティング AdverTimes 企画立案から実現まで『自分基点』のプロモーションのつくり方 https://www.advertimes.com/20230322/article414235/ 内山奈月 2023-03-22 01:44:56
マーケティング AdverTimes 大阪広告協会賞に日本ハム、佐治敬三賞はCMプランナーの細田佳宏氏に https://www.advertimes.com/20230322/article414261/ 佐治敬三 2023-03-22 01:31:14
GCP Cloud Blog JA 日立製作所:品質管理に Visual Inspection AI を利用した画像認識を導入し PoC で不具合判別率 100% を達成 https://cloud.google.com/blog/ja/topics/customers/hitachi-using-visual-inspection-ai-for-quality-control/ 日立製作所品質管理にVisualInspectionAIを利用した画像認識を導入しPoCで不具合判別率を達成様々な分野で先進的な製品やサービスを展開している総合電機メーカーの株式会社日立製作所以下、日立製作所。 2023-03-22 01:10:00

コメント

このブログの人気の投稿

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