投稿時間:2023-02-22 20:13:08 RSSフィード2023-02-22 20:00 分まとめ(15件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
js JavaScriptタグが付けられた新着投稿 - Qiita paizaラーニング レベルアップ問題集 新・Bランクレベルアップメニュー JavaScript 【全探索 3】+1, -1, '1'+, +'1' https://qiita.com/ZampieriIsa/items/4e325e40c9b56d0bcb71 javascript 2023-02-22 19:51:53
Linux Ubuntuタグが付けられた新着投稿 - Qiita Ubuntu do-release-upgrade https://qiita.com/hidenorly/items/554c4cfbac562c030077 available 2023-02-22 19:31:35
海外TECH DEV Community 7 Best Practices for Keeping a React Project Clean and Efficient https://dev.to/tyaga001/7-best-practices-for-keeping-a-react-project-clean-and-efficient-1ee3 Best Practices for Keeping a React Project Clean and Efficient A Step by Step Guide to Organising a React Project As a React developer you know that the key to creating a successful project is keeping your code organised and easy to understand In this guide I ll share my top tips and tricks for organising your React code intuitively and efficiently I ve got the scoop on keeping your codebase running like a well oiled machine from creative folder structures to clever naming conventions So why wait Let s dive in and start optimising your project today IntroductionAs a software engineer with over years of experience I ve worked on various exciting projects for companies such as Disney T Mobile Barclays and Accenture I ve learned the value of having a logical and clear code structure throughout my career especially on large scale projects where a lot of code can be tracked I ve tried out different structures and found that depending on the project s size and complexity some work better than others For example on a large project for Accenture I implemented a combination of feature based and module based folders to keep my code organised and easy to navigate This allowed me to maintain a clear separation of concerns and helped me stay efficient as I worked on the project Again there s no one size fits all approach to code organisation and the specific structure that works best for your project will depend on your particular needs and preferences But by following some best practices and staying organised you can set your project up for success and streamline your workflow as a developer Ideal Folder StructureAssuming you re going to create the next app similar to Facebook an ideal folder structure would look like this In this code structure a large scale React app that resembles a social media platform like Facebook is designed to be scalable maintainable and easy to navigate The structure is organised into an src directory containing the React app s source code The actions and reducers folders contain Redux specific code The components folder contains the React components for the app The styles folder contains CSS styles The utils folder contains utility functions The views folder contains higher level components responsible for rendering specific pages or sections of the app The App js file contains the root component of the app The index js file is responsible for rendering the root component and mounting it to the DOM The package json file lists the dependencies for the projectThe README md file provides documentation for the project Overall this code structure is designed to support the development of a large scale React app with a complex feature set and a large codebase The use of Redux for state management and the inclusion of utility functions and higher level views further help to improve the scalability and maintainability of the app I like how Adrian organizes his ongoing projects Naming ConventionsIn the code structure above I used several naming conventions to improve the readability and understandability of the code For example I used camelCase for variables and functions such as fetchPosts and updateProfile This standard convention in JavaScript makes it easier to read the code I also used PascalCase for components such as ProfilePage and PostList This standard React convention helps distinguish components from other types of code The actions folder contains code related to Redux actions The components folder contains the React components for the app Overall consistent and descriptive naming conventions help improve the code s readability and understandability Debugging and Error HandlingFirst I made sure to use the React Developer Tools browser extension a valuable tool for debugging and understanding what s happening in a React app The extension allows you to inspect the component hierarchy view the current state and props of components and see what s happening behind the scenes import React from react import render from react dom class App extends React Component state count incrementCount gt this setState count this state count render return lt div gt lt h gt Count this state count lt h gt lt button onClick this incrementCount gt Increment lt button gt lt div gt render lt App gt document getElementById root I also made sure to use the console log function to output debug information This simple but powerful tool allows you to see what s happening in your code import React from react import render from react dom class App extends React Component state count incrementCount gt console log Incrementing count this setState count this state count render return lt div gt lt h gt Count this state count lt h gt In addition I used try catch blocks to catch and handle exceptions in my code Finally I regularly tested the app to catch any errors or issues that might arise By following these debugging and error handling strategies I could effectively troubleshoot and fix problems in the app which helped improve the codebase s stability and reliability Code SplittingCode splitting is a technique for optimising the performance of a React app by dividing the code into smaller chunks that can be loaded on demand Here are factors to consider when implementing code splitting in a React app Code splitting can improve the initial load time of an app by only loading the code needed upfront rather than loading the entire codebase at once Code splitting can be implemented using the React lazy and Suspense components which allow you to dynamically load components as they are needed Code splitting can be used with web pack and the import function to dynamically import code chunks at runtime To implement code splitting in a React app you can use the React lazy and Suspense components to dynamically load components as they are needed For example import React Suspense from react const HomePage React lazy gt import views HomePage const ProfilePage React lazy gt import views ProfilePage const FriendsPage React lazy gt import views FriendsPage function App return lt Suspense fallback lt div gt Loading lt div gt gt lt Switch gt lt Route exact path component HomePage gt lt Route path profile component ProfilePage gt lt Route path friends component FriendsPage gt lt Switch gt lt Suspense gt export default App In this example the HomePage ProfilePage and FriendsPage components are loaded dynamically using the React lazy and Suspense components By implementing code splitting you can help optimize your React app s performance and improve the user experience LintingLinting is the process of automatically checking your code for errors and inconsistencies Here are three key points to consider when using linting tools to improve code quality in a React app Linting tools can help to enforce coding standards and best practices by identifying and flagging errors and inconsistencies in your code Linting tools can be integrated with your code editor or build process to automatically check your code as you write it Linting tools can be configured to check for specific errors or issues and can be customized to suit the needs of your project To implement linting in a React app you can use a popular linting tool such as ESLint For example you can install ESLint by running the command npm install eslint and then integrate it with your code editor by installing the corresponding plugin After that you can configure it by creating a eslintrc file at the root of your project Here is an example of how you might configure ESLint to check for specific errors in a React app extends eslint recommended plugin react recommended plugins react parser babel eslint parserOptions ecmaVersion sourceType module ecmaFeatures jsx true rules react prop types off By using the linting tool and enforcing coding standards you can help to improve the quality of your code and ensure consistency throughout your codebase TestingTesting is an important aspect of software development because it allows you to ensure that your components are working as expected Here are five key points to consider when testing React components Testing can help to catch bugs and errors early in the development process which can save time and effort in the long run There are different types of tests that you can write such as unit tests integration tests and end to end tests each with its specific use cases Unit tests are focused on testing individual components or functions in isolation and checking their outputs Integration tests are focused on testing how different components and services interact with one another End to end tests are focused on testing the entire application as a user would interact with it There are various testing libraries you can use to write the test cases for your React code the most popular of them are Jest Enzyme and Cypress Jest is a JavaScript testing framework that can be used for unit tests and integration tests Enzyme is a JavaScript testing utility for React that makes it easy to assert manipulate and traverse your React Components output Cypress is an end to end testing framework that makes it easy to write run and debug tests for web applications Here is an example of how you might write a unit test for a simple React component using Jest and Enzyme import React from react import shallow from enzyme import MyComponent from MyComponent describe MyComponent gt it renders the correct text gt const wrapper shallow lt MyComponent text Hello world gt expect wrapper text toEqual Hello world This test uses the shallow function from Enzyme to render the MyComponent component and then uses Jest s expect function to check that the component s text content is as expected Here s an example of an end to end test that tests the login to the home page and sending a tweet functionality using Cypress describe Login and tweet functionality gt it logs in and sends a tweet gt cy visit http localhost login cy get input name username type myusername cy get input name password type mypassword cy get button type submit click cy url should include home cy get textarea name tweet type This is my new tweet cy get button type submit click cy get tweet should contain This is my new tweet In this example the test navigates to the login page of the app enters the login credentials submits the form and checks if it s redirected to the home page Then it types in the text area a new tweet clicks on the submit button and then checks if the tweet is present on the page This test simulates a user logging into the app navigating to the home page and sending a tweet Here are two out of the box strategies for testing React components that you could consider Snapshot Testing This is a technique for testing that involves taking a snapshot of the component s rendered output and comparing it to a reference snapshot If the reference snapshot and the current snapshot match the test passes This technique can be useful for catching unexpected changes to a component s output Visual Regression Testing This technique involves taking screenshots of the component s output and comparing it to a reference screenshot If the reference screenshot and the current screenshot match the test passes This technique can be useful for catching visual changes to a component s output Here s an example of how you might use Jest and Enzyme to take a snapshot of a component import React from react import renderer from react test renderer import MyComponent from MyComponent describe MyComponent gt it matches the snapshot gt const tree renderer create lt MyComponent gt toJSON expect tree toMatchSnapshot Here s an example of how you might use Cypress for visual regression testing describe MyComponent gt it matches the reference screenshot gt cy visit http localhost cy matchImageSnapshot By using these techniques you can catch unexpected changes in your components and ensure that they maintain consistency over time Type CheckingType checking is a technique for ensuring that variables and functions have the correct data types at runtime Here are two key points to consider when using type checking tools to improve code reliability in a React app Type checking can help to catch type related errors early in the development process before they cause problems at runtime This can save time and effort in the long run Type checking can improve the readability and maintainability of your code by providing clear and explicit information about the types of variables and functions There are different type checking tools you can use in a React project the most popular is TypeScript and PropTypes TypeScript is a typed superset of JavaScript that adds type annotations and interfaces to the language It can be used to write large scale projects and increase development speed PropTypes is a built in package that ships with React it allows you to specify the types of props for a component and it will check them at runtime Here is an example of how you might use TypeScript to define the types of props for a component import React from react type Props name string age number isStudent boolean const MyComponent React FC lt Props gt name age isStudent gt return lt div gt name is age years old and is a student isStudent yes no lt div gt Here is an example of how you might use PropTypes to define the types of props for a component import React from react import PropTypes from prop types const MyComponent name age isStudent gt return lt div gt name is age years old and is a student isStudent yes Importance of an Organised Folder StructureCode organisation is essential for the success of any project large or small A clear and logical folder structure helps keep your code organised easy to understand and maintain An organised codebase makes it easier to scale your project as it grows and evolves A clear and consistent organisation can improve the overall efficiency of a project An organised codebase can make it easier to onboard new team members and reduce the learning curve for new developers It s worth taking the time to carefully plan and implement a code organisation strategy that works well for your particular project Ignoring code organisation can lead to a cluttered hard to maintain codebase that is difficult to work with Code organisation is not a one size fits all proposition the specific structure that works best for your project will depend on its size complexity and other factors Adaptability and willingness to change your code organisation strategy as your project grows and evolves are critical Code organisation is an ongoing process and it s essential to periodically review and refactor your structure to ensure that it still serves your project s needs Don t Overthink About Folder StructureIf you re just starting a new project don t spend more than minutes deciding on a file structure Choose any approach and begin writing code You ll definitely reconsider after you ve written some real code ConclusionOrganising your React code and implementing best practices is not only a good idea but it s also an absolute must for any project that aspires to be maintainable and scalable A well structured codebase is a foundation upon which all further development will be built It s like a solid foundation of a building that supports the entire structure By following best practices like using a clear and consistent file and folder structure implementing naming conventions managing dependencies debugging and error handling testing and type checking you ll be able to write code that is not only functional but also a pleasure to work with gt It s like having a clean and organised office it makes you more productive and efficient So don t just take our word for it put these best practices into action and experience the difference for yourself If you know of any better practices please share them in the comments section Thank you for taking the time to read this and happy coding This post is sponsored by the wonderful people at Scrimba and was originally published here They provide an excellent platform for interactive coding tutorials courses and challenges designed to turn you into a web development superstar Now that you ve been equipped with the knowledge on how to organize and structure your React code it s time to take the next step by subscribing to my newsletter and following me on Twitter In addition if you found this blog post useful please share it with your friends and colleagues who might also benefit from it Your support helps me to continue creating valuable content for the tech community 2023-02-22 10:29:13
海外TECH DEV Community Improving image performance on the web. https://dev.to/seven/improving-image-performance-on-the-web-4lbf Improving image performance on the web I ve been benchmarking the performance of my blog for a while now and there s no doubt that the cover images I m using are going to keep having a negative impact on the overall interactivity of the blog I want to change that Although I ve already tried ーand I m still using ーan image CDN like Cloudinary to automate the process of optimizing these images on the fly I still want to retain the quality and also convert these images to modern image formats like WebP and AVIF which are acceptable on web browsers that support these said formats I ended up having a URL like the one below q v image jpgCloudinary provided a way for me to convert the images to modern image formats with the f auto flag and the q auto flag to set the quality of the image without having to manually compress the image by myself In the link above you ll notice that I appended a value ー ーto the q flag to reduce the quality The tradeoff of this approach is that as you re optimizing for faster page loads and a very good TTI ーTime To Interactive ーscore the more you reduce the quality of these images you re going to get less enormous network payload errors What I am saying here in essence is when you reduce the quality of an image You somehow reduce the size this is probably a result of the compression algorithm that is being used here There are Lossless image compression algorithms that you can use out there too without trading the quality of your images for lesser network payloads I d say that a proper OR recommended approach towards optimizing images for the web is to manually compress them with compression tools like TinyJPG or Squoosh before uploading them to your favorite image CDN Why you d ask me This is because after you ve compressed your images with a tool that doesn t use a Lossy image compression algorithm you d still retain the quality of your images and a substantial reduction in the size of your image without losing the important components of that image s data It is a win win situation for everyone Serving images locally Another approach would be to have all the images you want in the same codebase repository so you can access them without making unnecessary fetch calls to a remote server But the important thing to note when using this approach would be the manual optimization of these images before you use them So the method of doing this would be similar to how we normally reference images in plain Ol HTML with the image element lt img src public image name png jpg webp avif alt image description gt Since this approach of serving images locally can help eradicate the complexities of preconnect ing to the domain of the Content Delivery Network CDN of an image service provider like Cloudinary and its other counterparts ImageMin Akamai etc It provides a better way to avoid unnecessary large network payloads and reduces the time taken for these requests to be processed by the browser hence delivering an optimal experience to the users of your website When you don t use the preconnect value of the rel attribute in the lt link gt element the browser isn t completely aware of the appropriate magnitude of importance to give to these images when fetching them lt link rel preconnect href res cloudinary com gt Prioritizing the requests of image assets There s an update in the latest web standards that allows us to add a fetch priority to images This idea was also implemented in the native fetch API of the browser the idea behind this was to be able to manipulate or re order the way various browsers parse and fetch the resources of a web page And as images are a vital part of any website that uses them they have to be given utmost importance An example of this use case is with the LCP ーLargest Contentful Paint ーelement of a website which happens to be an image element most of the time lt img src public image name png alt image description priority high gt In Frontend frameworks like Next js the next image component accepts a boolean fetchPriority prop Take a look at it below import React from react import Image from next image import imageSource from path to image export default function ExampleComponent return lt Image src imageSource height width priority true gt The priority hint feature ensures that browsers fetch resources that are important for the usability of software ーweb apps amp websites ーon the web and these priority hints can be used when we re carrying out native fetch operations to speed up the process of getting the image resources Aside from the fact that we re already preconnect ing to the image service provider s CDN The priority object can receive any of these values high low and an empty string The absence of a priority property in the fetch options resolves to the default method of fetching the images An example of this in action can be seen in the snippet below where I m utilizing the API routes in Next js to generate a blurred version of the images on my blog as placeholders You ll notice how I assigned the high string to the priority property export const imageDataURL async url gt const data await fetch url priority high const blob await data blob return new Promise resolve gt const reader new FileReader reader readAsDataURL blob reader onloadend gt const blurData reader result resolve blurData Rendering responsive imagesTo further reduce the performance implications caused by images on a website you d need to start considering an approach that allows you to build for everyone Everyone in the sense that you d need to factor the devices of the users of your app into your process as you do not want to ship an image that does not correspond with the DPR ーDevice Pixel Ratio ーof your users in production Say an image has a dimension of px by px and you re sending this image as is to the user on a mobile device with a viewport dimension of px by px This means that the mobile browser of the user s device would still have to download that image with an aspect ratio that does not correspond with its viewport dimensions and if I m not wrong the dimensions of an image have an effect on the image s size When you ship images that are not responsive ーresponsive in this sense doesn t have to do with the layout of such images It refers to how the dimensions of an image are appropriately returned while considering the DPR of your end users ーyour website has a sudden and unfavorable impact on the mobile data plans that they re currently on because they d have to download the image that is not pruned down to their current device width The conventional way of accomplishing this feat would be to have multiple images for various viewport breakpoints with different dimensions and in turn pass them in the srcset attribute of the native lt img gt element like it is in the snippet below But for this to work appropriately you d need to add the sizes attribute in the image element too lt img src image jpg alt image description sizes max width px vw max width px vw vw srcset image w jpg w image w jpg w image w jpg w image w jpg w image w jpg w image w jpg w image w jpg w gt The sizes attribute in the snippet above can be used for layouts that have a list of cards with images in them in a by pattern A vivid example can be seen on my blog you can also take a look at the image below At a max width of px the image spans the full width of its parent container and on desktop screens or larger screens it takes half the width of the viewport with respect to the parent container You re probably wondering So I am expected to manually create different images for different viewports All this stress just for the benefit of an end user Well YES all this stress for the benefit of an end user and NO you don t really have to manually create these images Cloudinary has a responsive image breakpoints generator that you can use for this sole purpose All you have to do is upload the image of your choice and set the appropriate breakpoints in the UI and it ll generate the markup that you can add in the srcset attribute Compatibility with Frontend frameworksI m pretty sure the process of creating images that corresponds properly with the Device Pixel Ratio DPR of mobile devices is somewhat similar to how it would be done with the native HTML lt img gt element But the case is different when creating these images in a typical Next js app Although there s an approach that can be followed through from their docs it requires you to edit the next config js file with an array of deviceSizes and imageSizes properties like the one below module exports images deviceSizes imageSizes The snippet above is the default configuration if you don t specify them explicitly in your config file Next js falls back to that config But the catch here is even when I didn t specify these properties in my config file one would think everything would work fine right Well I was wrong when I checked my blog s page speed insight I kept getting this error below despite the fact that I ve also added my array of images via the srcSet attribute I found out from a discussion that I started in the Next js GitHub repo that the srcSet propType was omitted because Next js automatically optimizes your images for you Still their optimization approach doesn t suit my need since I have already optimized my images with Cloudinary I needed a way to ship images with their appropriate sizes on various device widths The snippet below is an excerpt of how the srcSet attribute is ignored in the Next js image component if unoptimized return src srcSet undefined sizes undefined const widths kind getWidths config width sizes const last widths length return sizes sizes amp amp kind w vw sizes srcSet widths map w i gt loader config src quality width w kind w w i kind join And a way to fix this would require you to set the boolean propType unoptimized to true in the Next js image component like so export default function Card data title cover image imageSet return lt Wrapper gt lt div className cover image gt lt Image alt title src cover image height width layout responsive placeholder blur blurDataURL blurHash priority true srcSet imageSet sizes max width px vw max width px vw vw unoptimized true gt lt div gt lt Wrapper gt PS This approach of serving responsive images may have changed since the release of Next js and there s been a vital improvement to the Image component Do check it out first before you try using this approach Improving Cumulative Layout ShiftsOne more way to add a tiny improvement to the performance of your images would be to consider greatly the CLS ーCumulative Layout Shift ーthat these images themselves cause on initial render This performance metric is among the many metrics that reduce your lighthouse score and somehow affect your page speed insights too An approach to fixing this image performance issue would be to use the aspect ratio CSS property on the img element The property determines the ratio between the image s height and width property ーa bit related to the Device Pixel Ratio you saw in the previous section ーinstead of explicitly setting the exact dimensions of the image img aspect ratio width You can read more about the values the property receives hereThe good thing about this approach is that before the image resource s is fetched from the remote server the browser gives a ratio of the space the image is expected to occupy So if you have an image element in a div with texts above and below it The image s space is reserved as is until it is completely fetched by the browser Since the goal to design and build for everyone should be our priority as Engineers one way to sort of provide a good user experience for people would be to add a perception for the person visiting your site that a particular image is still loading Rather than having a large space in the component you can set a background for the image so that people are aware that an element will be there in no time The image below illustrates what it looks like on my blog With the Next js image component you may not need to specify an aspect ratio when you re styling the component all you may just need to do is add a background to the element Final ThoughtsOptimizing your images before using any image CDN can help reduce those enormous network payloads and by doing so it reduces the time taken for your page to be interactive I sometimes refer to this process as having multiple layers of optimization and or compression of these images to modern web image formats A great tool I ll recommend is Squoosh because it provides a lot of customization for you when you want to optimize your images with its lossless image compression algorithm 2023-02-22 10:08:29
海外TECH Engadget Samsung's Bixby now supports text-to-speech in English calls https://www.engadget.com/samsung-bixby-text-to-speech-english-calls-103539690.html?src=rss Samsung x s Bixby now supports text to speech in English callsLast year Samsung introduced a feature called quot Text Call quot for Bixby with One UI which essentially transforms voice calls into written text and vice versa It was initially available in Korean but now the company has launched support for the feature in US English The feature lets users answer calls by typing a message that Bixby will then read out loud to the caller It can also transcribe what the caller says making it a pretty useful tool for those hard of hearing or for anyone taking a call in a noisy environment nbsp While Bixby has several voice options Samsung is giving users the capability to personalize the voice it uses to answer calls They can use the new Bixby Custom Voice Creator to record a few sentences allowing the assistant to analyze their voice and tone and then use artificial intelligence to mimic what they sound like At the moment though both features come with limitations Voice creator is only available in Korean on the Galaxy S series Meanwhile Text Call as a whole can only be accessed on Galaxy S devices the Z Fold and the Z Flip In addition to English support for Text Call Samsung has also rolled out the capability to customize Bixby s wake word into whatever the user wants The assistant can now also play music that fits whatever workout is playing on Samsung Health and save schedules on the Calendar app Finally Samsung has expanded the things it can do offline including setting timers taking screenshots and switching on the flashlight nbsp 2023-02-22 10:35:39
医療系 医療介護 CBnews 障害者差別解消法、7割超が「知らない」-内閣府が世論調査の概要を公表 https://www.cbnews.jp/news/entry/20230222190337 世論調査 2023-02-22 19:20:00
医療系 医療介護 CBnews 病床確保料「移行期間」に縮小、5類移行で-政府検討、入院調整は行政から現場主導へ https://www.cbnews.jp/news/entry/20230222183927 都道府県 2023-02-22 19:10:00
金融 金融庁ホームページ 入札公告等を更新しました。 https://www.fsa.go.jp/choutatu/choutatu_j/nyusatu_menu.html 公告 2023-02-22 11:00:00
ニュース BBC News - Home Shamima Begum bid to regain UK citizenship rejected https://www.bbc.co.uk/news/uk-64731007?at_medium=RSS&at_campaign=KARANGA grounds 2023-02-22 10:27:38
ニュース BBC News - Home Nurses set for 'intensive' talks with government after strike paused https://www.bbc.co.uk/news/health-64722953?at_medium=RSS&at_campaign=KARANGA college 2023-02-22 10:02:10
ニュース BBC News - Home British Steel plans to close ovens and cut 260 jobs https://www.bbc.co.uk/news/business-64729316?at_medium=RSS&at_campaign=KARANGA scunthorpe 2023-02-22 10:29:16
ニュース BBC News - Home North Korea food crisis looms behind displays of military prowess https://www.bbc.co.uk/news/world-asia-64701184?at_medium=RSS&at_campaign=KARANGA february 2023-02-22 10:47:51
ニュース BBC News - Home Prince Harry and Meghan Markle dismiss South Park lawsuit rumour https://www.bbc.co.uk/news/uk-64730600?at_medium=RSS&at_campaign=KARANGA couple 2023-02-22 10:35:16
IT 週刊アスキー リンクスインターナショナル、AMD Ryzen 7 6800U搭載の7型ハイエンドポータブルゲーミングPC「AYANEO GEEK」を発売 https://weekly.ascii.jp/elem/000/004/126/4126077/ amdryzenu 2023-02-22 19:30:00
IT 週刊アスキー 『龍が如く 維新! 極』が本日発売!幕末をもっと楽しむDLCも配信 https://weekly.ascii.jp/elem/000/004/126/4126081/ esxsxboxonepcwindowssteam 2023-02-22 19:30: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件)