ROBOT |
ロボスタ |
マクニカ/NVIDIA「NVIDIAの最新プラットフォームを解説するセミナー」開催 Omniverse、Isaac、AI Enterprise等を紹介 |
https://robotstart.info/2023/05/22/nvidia-macnica-seminar.html
|
|
2023-05-22 03:51:27 |
IT |
ITmedia 総合記事一覧 |
[ITmedia ビジネスオンライン] 働く人の76.9%「AIに仕事を奪われると思う」 年代別の特徴は? |
https://www.itmedia.co.jp/business/articles/2305/22/news098.html
|
itmedia |
2023-05-22 12:22:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia Mobile] 楽天モバイル公式 楽天市場店、iPhoneの最大20%値引きキャンペーン開催 |
https://www.itmedia.co.jp/mobile/articles/2305/22/news110.html
|
iphone |
2023-05-22 12:19:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia ビジネスオンライン] 「タワマン否定派」がじわじわ増えてきた理由 |
https://www.itmedia.co.jp/business/articles/2305/22/news109.html
|
itmedia |
2023-05-22 12:16:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia PC USER] キヤノンMJ、A4対応のエントリードキュメントスキャナー |
https://www.itmedia.co.jp/pcuser/articles/2305/22/news105.html
|
imageformular |
2023-05-22 12:03:00 |
TECH |
Techable(テッカブル) |
ALSI、WebフィルタリングサービスにAndroid向けの新機能をリリース |
https://techable.jp/archives/207839
|
android |
2023-05-22 03:00:50 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
NVIDIA NeMo Guardrailsとは? -情報まとめ その2- |
https://qiita.com/mana-murakami/items/28e9eea654b74a540a67
|
nemoguardrai |
2023-05-22 12:52:04 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
Stable Diffusionでの画像生成をPythonとWeb APIで実装してみた記録 |
https://qiita.com/nabata/items/153ed75192004420c2e2
|
chapter |
2023-05-22 12:26:23 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
「Reactとは」をおさらいしてみよう! |
https://qiita.com/omo_taku/items/ccd0420a6e44a13dd353
|
facebook |
2023-05-22 12:36:27 |
Linux |
Ubuntuタグが付けられた新着投稿 - Qiita |
Ubuntu22.04 + KVM + Cockpit |
https://qiita.com/engishoma/items/ae946d1ae7d5443d86bf
|
vgubuntulvsudoresizefsd |
2023-05-22 12:39:13 |
海外TECH |
DEV Community |
Part 3: Component Structure - Building Reusable and Maintainable Components in React! |
https://dev.to/sathishskdev/part-3-component-structure-building-reusable-and-maintainable-components-in-react-54n6
|
Part Component Structure Building Reusable and Maintainable Components in React Welcome to Part of our React Best Practices in series In this part we will explore the importance of component structure and how it contributes to creating components that are highly reusable modular and easy to maintain Building reusable and maintainable components in React is not just about writing code it s about adopting best practices and following sound architectural principles By carefully structuring our components adhering to the Single Responsibility Principle and embracing concepts like Atomic Design and Component Composition we can create code that is more modular easier to test and simpler to maintain This approach leads to a more efficient development process and ultimately results in high quality scalable React applications Let s consider an example where we have a Todo application implemented in React Bad code with multiple responsibilitiesimport React useState from react const TodoApp gt Handling state const todos setTodos useState const newTodo setNewTodo useState Handle input change const handleInputChange e gt setNewTodo e target value Handle todo logic const handleAddTodo gt if newTodo trim const updatedTodos todos newTodo setTodos updatedTodos setNewTodo const handleDeleteTodo index gt const updatedTodos todos filter i gt i index setTodos updatedTodos const handleCompleteTodo index gt const updatedTodos todos map todo i gt if i index return todo completed todo completed return todo setTodos updatedTodos It doesn t provide a clear separation of smaller reusable components return lt div gt lt h gt Todo App lt h gt lt input type text value newTodo onChange handleInputChange gt lt button onClick handleAddTodo gt Add Todo lt button gt lt ul gt todos map todo index gt lt li key index gt lt span style textDecoration todo completed line through none gt todo text lt span gt lt button onClick gt handleDeleteTodo index gt Delete lt button gt lt button onClick gt handleCompleteTodo index gt todo completed Mark Incomplete Mark Complete lt button gt lt li gt lt ul gt lt div gt Above codebase contains a single component that handles everything from rendering the UI to handling data and state management This monolithic approach leads to a lack of separation of concerns and violates the SRP and Atomic Design principles To improve the code we can follow the SRP and Atomic Design principles Single Responsibility Principle SRP This principle states that a class or component should have a single responsibility or single reason to change By keeping components focused on a specific task you improve code readability maintainability and reusability It promotes breaking down complex functionality into smaller focused parts that are easier to understand test and maintain It encourages components to have clear and specific responsibilities enhancing their reusability and maintainability It helps in avoiding tightly coupled components by keeping them focused on specific tasks Let s breakdown the monolith TodoInput Extract the input handling logic into a separate useTodoInput custom hook and component TodoInput Responsible for handling user input and adding new todos TodoList Extract the todo list handling logic into a separate useTodoList custom hook and component TodoList Responsible for rendering the list of todos TodoItem Move the rendering logic for individual todos into a separate TodoItem component Responsible for rendering an individual todo item By separating the state and event handling logic into custom hooks or components we ensure that each component has a following single responsibility Todo InputThe useTodoInput custom hook can manage the input state using the useState hook and handle the input change eventuseTodoInput js Responsible for manage state and UI eventsimport useState from react const useTodoInput onAddTodo gt const inputValue setInputValue useState const disabled setDisabled useState true const handleSubmit e gt e preventDefault onAddTodo inputValue clearInput const handleInputChange e gt const value e target value setInputValue value setDisabled value trim const clearInput gt setInputValue setDisabled true return disabled inputValue handleInputChange handleSubmit export useTodoInput By utilizing custom hooks we can encapsulate the state and event handling logic in a reusable and modular way promoting code reusability and maintainability TodoInput jsxMove the JSX code related to the input field Add Todo button and todo list into separate JSX file TodoInput jsx Responsible for rendering TodoInput UIconst TodoInput onAddTodo gt const disabled inputValue handleInputChange handleSubmit useTodoInput onAddTodo return lt form className todo input onSubmit handleSubmit gt lt input type text value inputValue onChange handleInputChange placeholder Add a todo gt lt button className add button disabled disabled disabled disabled type submit gt Add lt button gt lt form gt By separating the JSX code into individual files we can improve code organization and readability making it easier to maintain and understand the component structure Like this we need to split our TodoItem and TodoList This refactoring approach adheres to the SRP by assigning single responsibilities to each component utilizes custom hooks for state and event handling and separates the JSX code into reusable components promoting modularity and maintainability in the React application Finally the component structure will look like below Component Stucturecomponents ├ー todo input │ ├ー TodoInput jsx│ ├ー useTodoInput js│ └ー TodoInput css├ー todo item │ ├ー TodoItem jsx│ └ー TodoItem css├ー todo list │ ├ー TodoList jsx│ ├ー useTodoList js│ └ー TodoList css└ー You can check it out the whole codebase in codesandbox We can further refactor this codebase using Atomic Design principles Atomic Design PrinciplesAtomic Design is a methodology for designing and organizing components in a hierarchical manner based on their level of abstraction and complexity It classifies components into five levels Atoms Molecules Organisms Templates and Pages with each level having a specific responsibility Atoms At the lowest level atoms represent the smallest and most basic UI elements such as buttons inputs or icons They have a single responsibility focusing on their visual appearance and basic functionality Molecules Molecules are combinations of atoms that work together to create more complex UI elements They have a slightly higher level of responsibility representing a group of related atoms Organisms Organisms are composed of molecules and atoms representing larger and more self contained sections of a user interface They have more complex behavior and may include state management and interaction logic Templates Templates are specific arrangements of organisms that provide a basic structure for a page or section They define the overall layout and composition of the UI Pages Pages are instances where templates are populated with real data creating actual content for the user to interact with Let s take an example of same todo app I will give an high level code design using the Atomic Design Pattern AtomsAtoms contains small reusable UI components like Button and Input Atoms Button jsxconst Button onClick children gt return lt button className button onClick onClick gt children lt button gt Input jsxconst Input value onChange gt return lt input className input type text value value onChange onChange gt Each atom has its own JavaScript file Button jsx Input jsx and CSS file Button css Input css MoleculesThe molecules directory contains combinations of atoms Button jsx that form more complex components such as the the TodoItem component Molecules TodoItem jsxconst TodoItem todo onDelete onComplete gt return lt li className todo item gt lt span className todo completed completed gt todo text lt span gt lt Button onClick onDelete gt Delete lt button gt lt Button onClick onComplete gt todo completed Mark Incomplete Mark Complete lt Button gt lt li gt It has its own JavaScript file TodoItem js and CSS file TodoItem css OrganismsThe organisms directory contains larger more feature rich components such as the TodoForm and TodoList components Organisms TodoForm jsxconst TodoForm onAddTodo gt const inputChange addTodo useTodoForm return lt div className todo form gt lt Input value newTodo onChange inputChange gt lt Button onClick addTodo gt Add Todo lt Button gt lt div gt TodoList jsxconst TodoList todos onDeleteTodo onCompleteTodo gt return lt ul className todo list gt todos map todo index gt lt TodoItem key index todo todo onDelete gt onDeleteTodo index onComplete gt onCompleteTodo index gt lt ul gt They are composed of molecules and or atoms and have their own JSX TodoForm jsx TodoList jsx Custom Hooks useTodoForm js and CSS files TemplatesThe templates contains components that provide the overall structure of a page or layout In this case the Todo template is responsible for rendering the TodoForm and TodoList components Templates Todo jsxconst Todo gt const todos addTodo deleteTodo completeTodo useTodo return lt div className todo app gt lt h gt Todo App lt h gt lt TodoForm onAddTodo addTodo gt lt TodoList todos todos onDeleteTodo deleteTodo onCompleteTodo completeTodo gt lt div gt It has its own JSX file Todo jsx and Custom Hook useTodo js and CSS file Todo css PagesThe pages directory components that represent a specific page in the application In this example there is a HomePage component that serves as the main entry point of the Todo app Pages HomePage jsconst HomePage gt return lt div className home page gt lt TodoApp gt lt div gt This example demonstrates how the Todo app codebase can be structured using the Atomic Design pattern Each component is responsible for a single concern and they can be easily reused and composed to build the complete Todo app Final ThoughtsWhen designing your React app it s essential to avoid assigning multiple responsibilities to a single component Here are some practical strategies to help you achieve a cleaner and more maintainable codebase Identify clear responsibilities Clearly define the purpose of each component Break down complex functionalities into smaller focused components with well defined responsibilities Separation of concerns Separate concerns by dividing your app into distinct components based on their functionality Each component should have a specific role and handle a single responsibility Component composition Instead of building large components that handle multiple tasks compose your UI by combining smaller reusable components This promotes reusability and modularity Single task functions Extract complex logic from components into separate functions or utility modules By encapsulating specific functionalities in separate functions you keep your components focused on rendering and UI related tasks Follow the SOLID principles Adhere to SOLID principles such as the Single Responsibility Principle SRP which states that a component should have only one reason to change This principle helps you design components that are focused maintainable and easier to test Use custom hooks Extract common logic into custom hooks that can be shared across components This allows you to reuse logic without introducing unnecessary complexity to individual components Modular architecture Organize your codebase using a modular architecture such as the feature based folder structure This approach promotes separation of concerns and helps in keeping components focused on their specific responsibilities By consciously designing your React app with these practices in mind you can avoid assigning multiple responsibilities to components This leads to cleaner more maintainable code that is easier to understand test and extend Bonus Component HierarchyIt is generally recommended to follow a specific component hierarchy to maintain consistency and readability in your codebase Component Hierarchy External dependenciesimport React useState useRef useEffect from react import PropTypes from prop types import from lodash Internal dependenciesimport TodoItem from TodoItem import TodoUtils from utils import useTodo from hooks import withTimer from hoc import TodoType from enums Stylesheetsimport Component css import styles common css Assetsimport todoImage from assets todoImage png const Todo gt State logic const todos setTodos useState Ref const inputRef useRef null Variable const title Todo List Custom hook const addTodo useTodo Higher order component const timer withTimer TodoItem Component lifecycle methods useEffect useEffect gt Component render return lt div gt Component JSX lt div gt Todo propTypes Prop types declaration export Todo By structuring your component hierarchy in a consistent and organized manner you can improve the readability maintainability and scalability of your React app A well defined hierarchy helps developers navigate the codebase understand component relationships and make modifications efficiently Stay tuned for more tips and tricks on building high quality React applications in my future blog posts Happy coding |
2023-05-22 03:30:00 |
海外TECH |
DEV Community |
ESLint: The Hows, Whys, and Who Behind It |
https://dev.to/philipjohnbasile/eslint-the-hows-whys-and-who-behind-it-5fkl
|
ESLint The Hows Whys and Who Behind ItESLint recognized by many developers is a robust code linting tool designed explicitly for JavaScript But where did it originate and what drove its creation Let s explore its inception and understand its role more deeply The narrative begins with Nicholas C Zakas an experienced Box developer who conceptualized ESLint in June Unfulfilled by JSHint the prevalent linting tool then Nicholas craved a device that offered plugin support and extensibilityーattributes JSHint fell short on His inspiration stemmed from a surprising source the PHP linter crafted at Box built upon an Abstract Syntax Tree AST This approach contrasted with the regular expression based JavaScript linting tools in vogue offering a fresh means to scrutinize code Ariya Hidayat a respected software industry figure utilizing AST in JavaScript further motivated him Invited to present a talk at Box Ariya introduced his creation Esprima a high performance standards compliant ECMAScript parser crafted in JavaScript He also highlighted Yusuke Suzuki s contributions who constructed Estraverse and Escope atop Esprima These tools vital for ECMAScript traversal and scope analysis originated from the impactful esmangle project Influenced by Ariya s lecture and the open source projects Nicholas dedicated his leisure time to developing ESLint Incorporating elements from Esprima Estraverse and Escope he birthed a robust tool grounded on one cardinal principle pluggability ESLint offers the extensibility and plugin support that JSHint lacked signaling a leap forward in JavaScript linting tools When you next engage ESLint for your coding project remember to appreciate Nicholas and the community that invested their time and effort into this invaluable resource Today ESLint transcends the role of a mere linting tool it s central to the JavaScript development sphere Its capacity to scrutinize code for potential errors and enforce coding standards has facilitated developers in crafting cleaner error free code and advocated superior coding practices across teams and organizations Nonetheless ESLint s existence hinged on its predecessor s limitations The lack of plugin support in JSHint prompted Nicholas to reimagine traditional linting tools The pluggable characteristic of ESLint distinguishes it enabling developers to tailor the device to their specific requirements by integrating custom rules formats and configurations Adopting Abstract Syntax Tree AST proved pivotal in ESLint s evolution With AST as its backbone ESLint dissects JavaScript code into its essential components for analysis offering a scrutiny level that traditional regular expression based linting could not achieve The influence of Ariya Hidayat s Esprima and Yusuke Suzuki s Estraverse and Escope is evident in this innovative approach Indubitably ESLint s growth showcases the strength of the open source community From Ariya s enlightening lecture to the influences of the Esprima Estraverse and Escope projects Nicholas could amalgamate these resources into ESLint The result is a tool built on the commitment and dedication of numerous brilliant minds steered by Nicholas ESLint is more than just a tool it s a solution shaped by the needs of developers and the evolution of JavaScript forged by the community The next time you employ ESLint reflect on its story a tale of innovation inspiration and community collaboration As we extend our gratitude to Nicholas and the other contributors we also recognize the power of open source projects in advancing technology Moreover Nicholas C Zakas has significantly influenced the JavaScript and web development community through ESLint and various other projects books and presentations Nicholas is an esteemed author of several influential books on JavaScript and web development including Professional JavaScript for Web Developers High Performance JavaScript and Understanding ECMAScript These resources have provided countless developers with a deeper understanding of JavaScript and enhanced their coding efficacy Before pioneering ESLint Nicholas was a pivotal contributor to Yahoo s YUI Yahoo User Interface library a free open source JavaScript and CSS library designed for crafting richly interactive web applications His contributions to YUI significantly influenced its evolution into one of the most robust and widely adopted JavaScript libraries of its time Furthermore Nicholas has actively participated in JavaScript s development as a language He has been involved with TC the group responsible for evolving JavaScript contributing to discussions about language enhancements and future directions A familiar face at web development conferences Nicholas regularly shares his insights on JavaScript and web development offering invaluable expertise to his peers His blog Human Who Codes is a reservoir of articles spanning various topics from JavaScript best practices to comprehensive insights into the web development industry Nicholas s contributions stretch beyond specific tools or libraries His influence resonates throughout the JavaScript community where he has advocated for quality performance and comprehensibility His efforts mainly through ESLint have significantly improved the JavaScript ecosystem and the quality of web applications we interact with daily To sum up ESLint s origin story and Nicholas s broader contributions to JavaScript reflect the power of open source collaboration and the relentless drive of individuals to improve and evolve the tools we use Using ESLint and other instruments from such dedication we partake in a shared tradition of innovation and community driven technological development This commitment to continuous improvement is not just about making individual coding tasks more accessible or more efficient but about elevating the entire field of web development Sharing tools best practices and innovative solutions helps to drive collective knowledge forward enabling us to build better more complex and more effective digital solutions for an increasingly interconnected world Nicholas s passion for educating and sharing knowledge is also evident in his advisory role with various software organizations helping to shape development practices and standards His influence goes beyond his writings and extends into these organizations further emphasizing his significant impact on the industry In addition Nicholas has been instrumental in facilitating better programming practices by developing and promoting coding standards These standards often enforced by tools like ESLint have increased code maintainability and reduced errors leading to higher quality software projects His dedication to promoting these practices underscores his commitment to quality in the field Nicholas s ongoing contributions to the JavaScript community exemplify the ethos of the open source movement collaboration knowledge sharing and constant improvement By creating and maintaining tools like ESLint he has helped to elevate JavaScript as a language and empowered countless developers to produce better code While ESLint is a testament to Nicholas C Zakas s ingenuity and commitment to the JavaScript community it also symbolizes the broader potential of open source projects Each time we use tools like ESLint we benefit from a communal effort to streamline and improve the programming process Whether you have years of experience in development or are just starting out in the field remember that each line of code you write contributes to this vast ongoing project of technological advancement This exploration of ESLint s origins and the contributions of Nicholas C Zakas provides just a glimpse into the vibrant world of open source JavaScript development As we advance in our digital age it s important to remember and acknowledge the individuals and communities that work behind the scenes passionately driving the technology that shapes our world |
2023-05-22 03:20:57 |
ニュース |
BBC News - Home |
US debt ceiling: Joe Biden and Kevin McCarthy seek to break impasse |
https://www.bbc.co.uk/news/world-us-canada-65666067?at_medium=RSS&at_campaign=KARANGA
|
republican |
2023-05-22 03:20:06 |
ニュース |
BBC News - Home |
Hinge and Bracket star George Logan dies aged 78 |
https://www.bbc.co.uk/news/entertainment-arts-65667911?at_medium=RSS&at_campaign=KARANGA
|
musical |
2023-05-22 03:49:44 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
【社説】ウクライナにようやくF16戦闘機供与 - WSJ発 |
https://diamond.jp/articles/-/323309
|
社説 |
2023-05-22 12:14:00 |
GCP |
Google Cloud Platform Japan 公式ブログ |
Vertex AI と PyTorch を使用して、わずか 4 ステップでジェネレーティブ AI モデルをデプロイ |
https://cloud.google.com/blog/ja/products/ai-machine-learning/get-your-genai-model-going-in-four-easy-steps/
|
PyTorchとVertexAIを使用すると、本番環境でのモデルのトレーニング、デプロイ、オーケストレーションが非常に簡単になることがおわかりいただけるでしょう。 |
2023-05-22 03:10:00 |
ニュース |
Newsweek |
大きな成果がないと見られていたG7だが、「新・対中戦略」は本格化する |
https://www.newsweekjapan.jp/stories/world/2023/05/post-101692.php
|
最近ではアメリカの対中投資を規制する仕組みの導入を目指し、広島で開催された主要カ国首脳会議Gサミットの直後に、計画の概要を示す大統領令が発効する見込みだ。 |
2023-05-22 12:35:17 |
ニュース |
Newsweek |
中国のLGBTQ支援に逆風が吹き始めた──人権擁護団体、活動停止を発表...「不可抗力」の意味とは? |
https://www.newsweekjapan.jp/stories/world/2023/05/post-101695.php
|
中国のLGBTQ支援に逆風が吹き始めたー人権擁護団体、活動停止を発表「不可抗力」の意味とは年の設立以来、中国におけるLGBTQの人権擁護に尽力してきた北京LGBTセンターが月日、活動停止を発表した。 |
2023-05-22 12:20:00 |
ニュース |
Newsweek |
ベラルーシ・ルカシェンコ大統領に健康不安説...「弱々しい姿だ」と話題...国際情勢への影響は? |
https://www.newsweekjapan.jp/stories/world/2023/05/post-101694.php
|
ベラルーシ・ルカシェンコ大統領に健康不安説「弱々しい姿だ」と話題国際情勢への影響は月日、モスクワで開かれた対独戦勝記念式典に出席していたベラルーシのルカシェンコ大統領に注目が集まった。 |
2023-05-22 12:10:00 |
マーケティング |
MarkeZine |
【耳から学ぶ】インフレに打ち勝つ価格戦略。日本企業が値上げに踏み切れないのはなぜ? |
http://markezine.jp/article/detail/42307
|
価格戦略 |
2023-05-22 12:30:00 |
IT |
週刊アスキー |
高度な3D立体成型と緻密なカット処理でXperia 1 Vをガードする超軽量・薄型ケース |
https://weekly.ascii.jp/elem/000/004/137/4137136/
|
imlightcaseduroforxperiav |
2023-05-22 12:30:00 |
GCP |
Cloud Blog JA |
Vertex AI と PyTorch を使用して、わずか 4 ステップでジェネレーティブ AI モデルをデプロイ |
https://cloud.google.com/blog/ja/products/ai-machine-learning/get-your-genai-model-going-in-four-easy-steps/
|
PyTorchとVertexAIを使用すると、本番環境でのモデルのトレーニング、デプロイ、オーケストレーションが非常に簡単になることがおわかりいただけるでしょう。 |
2023-05-22 03:10:00 |
コメント
コメントを投稿