AWS |
AWS Japan Blog |
Amazon CloudWatch アラームの大規模なクリーンアップを自動化する |
https://aws.amazon.com/jp/blogs/news/automating-amazon-cloudwatch-alarm-cleanup-at-scale/
|
amazoncloudwatch |
2023-05-18 12:34:08 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
GitHub Copilot Labs で R から色々翻訳してもらったら、なんだか色んな言語を喋れる気分になって楽しかった話 |
https://qiita.com/taiyodayo/items/1a193c4e60483c8a740f
|
githubcopilot |
2023-05-18 21:59:38 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
JavaScriptのthisに沼って仕様書にまで沈んだ話 |
https://qiita.com/amagiyuri/items/eaecf0f1f44a4124320b
|
javascript |
2023-05-18 21:08:15 |
技術ブログ |
Developers.IO |
2024年4月1日に民間企業にも義務化される「合理的配慮」とアクセシビリティの関係を障害者差別解消法から解説します |
https://dev.classmethod.jp/articles/explaining-reasonable-accommodation-accessibility-under-disability-discrimination-act-private-sector/
|
accessibilityawarenessday |
2023-05-18 12:30:53 |
海外TECH |
MakeUseOf |
5 Tools to Review Any Website’s SEO for Free |
https://www.makeuseof.com/review-website-seo-tools/
|
examples |
2023-05-18 12:30:18 |
海外TECH |
MakeUseOf |
How to Flip a Photo on Android |
https://www.makeuseof.com/flip-photos-android/
|
quick |
2023-05-18 12:15:17 |
海外TECH |
DEV Community |
How to use Zustand |
https://dev.to/refine/how-to-use-zustand-3okc
|
How to use ZustandAuthor Chidume Nnamdi IntroductionRedux changed the game in the global management system It was so successful that it was widely adopted and used as the ideal state management system in any framework Not only in the framework but its principle still serves greatly in software development Almost all developers have used Redux to manage their global state and we can all attest to how powerful fast and maintainable it is to use Redux as the global state management tool It makes debugging very easy and our app is predictable Yes Redux took the grand stage in global state management but there is a new kid on the block This new kid is poised and ready to capture the audience of the global state management system It comes packing a powerful punch and is armed to the teeth Its name is Zustand With the arrival of Zustand and the goodies it brings will it suffice to say that Redux reign is coming to an end In this article we will deep dive into Zustand We will learn about this kid to understand how it works its state management technique and how it will take the state management world by storm Steps we ll cover What is Zustand Getting started with ZustandBuild a To do app using Zustand What is Zustand A small fast and scalable barebones state management solution using simplified flux principles Has a comfy API based on hooks and isn t boilerplates or opinionated Zustand is a small unopinionated state management library built by Jotai and React spring It has a comfy API based on hooks and isn t opinionated Zustand is open source with a large community of users and support developers working round the clock to make Zustand stable It sits on Github with stars Zustand is very different from Redux in terms of how it is used Zustand is simple and un opinionated it does not wrap your app in content providers like how we do with React Redux It mainly uses hooks as a means of communicating back and forth with the state At its core Zustand embraces the concept of a single source of truth where the entire application state is stored in a centralized store This store is composed of state slices which are individual units of state that represent different parts of the application Each state slice is defined as a separate store allowing for modularity and encapsulation of related state properties and their associated actions Working with Zustand you will need less boilerplate for it and its state management is centralized and action based Zustand promotes immutability by default ensuring that state updates are handled in an immutable fashion When updating the state you create a new state object rather than modifying the existing state directly This approach simplifies state management prevents common mutation related bugs and enables efficient change detection and re rendering in React components Another notable feature of Zustand is its built in support for subscriptions and selective reactivity Components can subscribe to specific state slices and be automatically re rendered when those slices change Zustand uses a fine grained dependency tracking mechanism based on proxies allowing for highly efficient updates and minimizing unnecessary re renders In the next section we will learn how to install and use Zustand in our project Open source enterprise application platform for serious web developersrefine new enables you to create React based headless UI enterprise applications within your browser that you can preview tweak and download instantly By visually combining options for your preferred React platform UI framework backend connector and auth provider you can create tailor made architectures for your project in seconds It feels like having access to thousands of project templates at your fingertips allowing you to choose the one that best suits your needs Getting started with ZustandWe know that Zustand is a JavaScript library that runs on Nodejs So we will need some basic tools to be installed on your machine before we start Nodejs We need the Nodejs binaries installed in our system Go over to and install the binaries meant for your machine npm or yarn These are Node Package Managers they help in maintaining and managing the dependencies and the Nodejs environment of our project npm comes bundled with the Nodejs binaries so once you install Nodejs you don t need a separate installation for npm Yarn can be installed by running npm i yarn g Let s create a Nodejs project mkdir zustand prjcd zustand prjnpm init ymkdir zustand prj This command creates a new directory named zustand prj in the current location It is equivalent to make directory The zucd zustand prj This command changes the current working directory to zustand prj By running this command you will navigate into the newly created directory npm init y This command initializes a new Node js project within the zustand prj directory The npm init command is used to generate a package json file which is a manifest file that describes your project s metadata and dependencies The y flag is added to automatically accept all default options without prompting for user input It is a shortcut for answering yes to all the initialization questions To install the zustand library we run the below command npm install zustand or yarn add zustandThis command installs the zustand library in our project To use zustand we have to import a create function import create from zustand This function is called with a callback function and it returns a custom hook The callback function passed to it is where we will define our state and the functions we can use to manipulate the state The state and the functions are all in an object returned by this callback function Let s see an example const useCounter create set gt return counter incrCounter gt set state gt counter state counter See that the create function passes a set function to the callback function This set function is a function used to manipulate the state in the store States in zustand can be primitives objects or functions In our above example we have two states in our store counter and incrCounter The useCounter is a custom hook we can use this hook in our components and we will be able to get the latest state in them If we use the hook in components A B and C Any change done to the state in B will be reflected in both A and C and they will all re render to reflect the new changes The custom hook returned by the create acts similarly to useAppSelector in React Redux it lets you select a slice of state from the store You call the hook and pass it a callback function This function is called by the hook internally and passes the current state to it So we will then get this state and return the part of the state we want Let s see an example const counter useCounter state gt state counter See that we called the useCounter hook and passed a callback function to it Then we expect a state from the hook and then return the counter part of the state We can then display the counter const DisplayCounter gt const counter useCounter state gt state counter return lt div gt Counter counter lt div gt Now we want to create a component where we can increase the value of the counter state const CounterControl gt const incrCounter useCounter state gt state incrCounter return lt div gt lt button onClick incrCounter gt Incr Counter lt button gt lt div gt This is a separate component from where we increase the value of the counter state See that we sliced out the incrState function from the state and we set it to the onClick event of the button This will increase the counter state when the button is clicked See how the components are independent of each yet they can see the current state from the store Whenever we click the Incr Counter button in the CounterControl component the DisplayComponent will re render to display the newest counter state value Let s see how we use them const App gt return lt gt lt DisplayCounter gt lt CounterControl gt lt gt They are independent of each other yet magically connected by zustand This gives React Redux a run for its money because trying to re create this small state in Redux React will take more code to set up First we will create a store We will wrap either the App component or its children in a Content Provider and pass the store to the Context Provider via a store props We will import useSelector useDispatch in any component we wish to use in the store To get a slice of the state we will call the useSelector with a callback function To dispatch an action to the store we will use the useDispatch hook It s quite lengthy but with Zustand it s oversimplified Returning the whole stateNow when we call the custom hook returned by the create function without a callback function the hook will return the whole state of the store const state useCounter See that we called the useCounter hook with no callback function so in this case the function will return the whole state in the store The state holds the whole state in the useCounter store We can get the counter state by doing this state counter We can also call the incrCounter state function state counter state incrCounter MemoizationWe can memoize our zustand store Memoization is an optimization technique used to optimize the execution of functions by caching the results of expensive or time consuming function calls It involves storing the return value of a function associated with a specific set of input parameters so that if the function is called again with the same parameters the cached result can be returned instead of re evaluating the function The goal of memoization is to improve performance and efficiency by avoiding redundant computations Now zustand gives us the ability to add memoization to the custom hook it returns to us It exports a shallow function that we can use to add memoization to our state picks import shallow from zustand shallow Still using our useCounter as an example let s say we want to get the counter state from the store We do this DisplayComponentconst counter useCounter state gt state counter Now let s say the initial state of the counter is when the counter state is updated using the incrCounter the DisplayComponent will be re rendered Now if the updated value of the counter is we will see that it is unnecessary to re render the DisplayCounter component How do we stop this unnecessary re rendering from occurring when the previous state and the next state are equal Zustand directs us to pass a comparator function as a second parameter to the custom hook This comparator function will compare the previous slice state and the next slice state if both are the same the component will not re render else the component will re render This is exactly what other React hooks do useEffect useMemo and useCallback The shallow function is a comparator function provided to us by Zustand It shallowly compares the two state slices using the shallow equality operator const counter useCounter state gt state counter shallow See we passed the shallow function as a second parameter to the useCounter hook On each state change in the store the shallow will determine if the component will re render based on the previous and next value of the counter state We can use our custom made comparator if we don t trust the shallow function to do the job The comparator function takes two parameters the first parameter is the previous value of the state slice while the second parameter is the next value of the state slice previousState nextStateSlice gt Inside this function is where we do our comparing and return the result Returning true will make the hook skip the component from re rendering while returning false will make the component re render Let s create our comparator function for the counter state slice previousCounter nextCounter gt previousCounter nextCounter This uses the equality operator to check if the two are the same It returns a Boolean Let s plug it back into the useCounter hook const counter useCounter state gt state counter previousCounter nextCounter gt previousCounter nextCounter Now we have memoized our useCounter hook With this we have made our application a bit faster with no more unnecessary re renders Updating the whole stateWe have only talked about getting the state from the store but we have not delved into how to set the state We only saw it briefly when we created the useCounter hook earlier on Now we will see how to update the state We learned that zustand passes a function to the callback function passed to the create function This function widely accepted to be referred to as set is used to update all or parts of the state Let s look into the incrCounter state function const useCounter create set gt return counter incrCounter gt set state gt counter state counter Here we are passing a callback function to the set function The set function will call this function and pass it the state as an argument then use the result of the function to update the state See that in the callback function we are returning an object with a counter property The set function uses the properties found in the object to know the properties in the state to update We see that when we pass a function to the set function as an argument the set function expects that we return an object We can pass an object to the set function set counter This will update the counter state value to Clear the entire stateWe can clear the state in a zustand store by passing an empty object to the set function set true This will clear the state and the actions What are actions Actions are functions that are part of the state in a zustand store They are like dispatch actions in React Redux they are used to effect changes in the store For example our incrCounter is an action we call the set function inside it to update the counter state Using async actionsActions in zustand also support asynchronicity In fact according to Zustand docs zustand does not care if your action is asynchronous or not We can perform an asynchronous function in an action For example we can make an HTTP request to an endpoint from our action and update the state with the result from the HTTP call Let s show an example const useCounter create set gt return counter incrCounter async gt const data await axios get counter set counter data counter See that in the incrCounter we made it an asynchronous function by using the async keyword Inside the function we made a call to an counter endpoint and use the set function to update the value of the counter in the state Build a To do app using ZustandNow we have learned the basics of zustand and its API We will create a To do app using Zustand The To do app will be a React app while the Zustand will power our state management Let s start we will scaffold a React project using the create react app tool create react app todo appcd todo appNext we install zustand npm install zustandThe first thing we create our hook store import create from zustand const useStore create set gt todos addTodo text gt set state gt todos state todos id Date now text completed false toggleTodo id gt set state gt todos state todos map todo gt todo id id todo completed todo completed todo deleteTodo id gt set state gt todos state todos filter todo gt todo id id export default useStore See we have a todos state This will hold an array of our todos We have three actions addTodo toggleTodo and deleteTodo The addTodo action adds new todo to the todos state the toggleTodo action toggles the completed state of a todo The deleteTodo removes a todo from the array state Now let s build the components DisplayTodosThis component will have one job It will render the todos state const DisplayTodos gt const todos deleteTodo useStore state gt return todos state todos deleteTodo state deleteTodo return lt ul gt todos map todo gt lt li key todo id style textDecoration todo completed line through none onClick gt toggleTodo todo id gt todo text lt button onClick gt deleteTodo todo id gt Delete lt button gt lt li gt lt ul gt export default DisplayTodos We sliced off the todos array from the state and used the Array map method to render the todos also we sliced off the deleteAction The Delete button removes each todo from the list it does this by calling the deleteAction action with the id of the todo clicked Now let s build the component where we can add a todo to the list TodosControlconst TodosControl gt const addTodo useStore state gt state addTodo const text setText useState function handleSubmit e e preventDefault addTodo text setText return lt form onSubmit handleSubmit gt lt input type text value text onChange e gt setText e target value gt lt button type submit gt Add lt button gt lt form gt export default TodosControl This component provides us a form where we input a todo and add it to the state store We have a state text that holds the text we type in the input element Then the handleSubmit function is called when the form is submitted via the Add button Inside the handleSubmit function the addTodo is called passing in the text in the text state as an argument This will create and add a new todo to the todos state Bringing them all together const App gt return lt gt lt DisplayTodos gt lt TodosControl gt lt gt export default App ConclusionWe have come a long way Zustand is interesting and freakingly minimal and basic to use Mind you what we learned here is just the basics the power of Zustand is yet to be covered in total and it runs deep Let s recap We started by introducing Zustand how it works and how it differentiates itself from the world popular Redux Next we saw how to install the Zustand library we learned also how to set up a state in it and how to use the actions We learned how to set up async operations in actions how to update a state and how to get slices off a state |
2023-05-18 12:31:46 |
Apple |
AppleInsider - Frontpage News |
It's impossible to compete with Apple, says third-party iPhone repair shops |
https://appleinsider.com/articles/23/05/18/its-impossible-to-compete-with-apple-says-third-party-iphone-repair-shops?utm_medium=rss
|
It x s impossible to compete with Apple says third party iPhone repair shopsDue to lengthy delays in parts processing and steep costs third party iPhone repair providers say that there is no practical way that they can compete with Apple s repair chain Right to Repair After facing increased pressure from legislators Apple created its independent repair provider program in It gave small companies an Apple sanctioned way to repair customers devices such as the iPhone using genuine Apple parts and tools Read more |
2023-05-18 12:52:53 |
Apple |
AppleInsider - Frontpage News |
Compared: Google Pixel 7a vs iPhone SE 2023 |
https://appleinsider.com/inside/iphone-se/vs/compared-google-pixel-7a-vs-iphone-se-2023?utm_medium=rss
|
Compared Google Pixel a vs iPhone SE Google recently revealed the budget Pixel a that competes price wise with the affordable iPhone SE Here s how their features stack up Pixel a and iPhone SEUnveiled at Google I O the Pixel a follows a similar concept to the iPhone SE aiming to deliver flagship level performance in an affordable package Apple released the third generation of the iPhone SE model in March with some of the same features Read more |
2023-05-18 12:47:10 |
Apple |
AppleInsider - Frontpage News |
Apple's headset drastically changed over time & top execs are skeptical |
https://appleinsider.com/articles/23/05/18/apples-headset-drastically-changed-over-time-top-execs-are-skeptical?utm_medium=rss
|
Apple x s headset drastically changed over time amp top execs are skepticalDespite the divergence of the upcoming Apple AR headset from the company s original vision and skepticism from executives Tim Cook himself is actively pushing the project forward Render of Apple headsetAnticipated to make its debut at WWDC in June the Apple VR and AR headset is poised to capture significant attention While much speculation has revolved around its hardware capabilities it appears that its array of features and functions could be equally extensive Read more |
2023-05-18 12:55:10 |
海外TECH |
Engadget |
YouTube is bringing 30-second unskippable ads to its TV apps |
https://www.engadget.com/youtube-is-bringing-30-second-unskippable-ads-to-its-tv-apps-121051897.html?src=rss
|
YouTube is bringing second unskippable ads to its TV appsIf you watch YouTube videos primarily on your TV you may soon come across second ads you won t be able to skip just like commercials on traditional TV channels The video platform has announced during its Brandcast event for advertisers that it s bringing second unskippable ads to connected TVs It will make the option available through YouTube Select which is a targeting option open to eligible clients who want to reach the audiences of the website s most popular channels YouTube says percent of Select impressions land on TVs so the new format will give advertisers the chance to show more of their services or products in a way that allows quot for richer storytelling quot If you already regularly see two second ads consecutively then the new format wouldn t make that much of a difference for you ーunless they show up more frequently of course The format is now generally available in the US and Canada and will expand worldwide later this year In addition to introducing longer non skips YouTube is also bringing quot pause experiences quot to connected TVs as an experiment Pause experiences are ads that show up when you hit pause on what you re watching similar to the promos Hulu launched in They re expected to be highly visual and even interactive and they could include QR codes you can scan to perhaps visit the brands website or social media channels In the image below for instance you ll see an ad encouraging you to scan a QR code to get a percent discount YouTubeThis article originally appeared on Engadget at |
2023-05-18 12:10:51 |
Cisco |
Cisco Blog |
Combating Ransomware with Security Service Edge |
https://feedpress.me/link/23532/16131964/combating-ransomware-with-security-service-edge
|
Combating Ransomware with Security Service EdgeEver since the WannaCry attack in ransomware has remained one of the most significant cyber threats worldwide SSE disrupts ransomware Find out more |
2023-05-18 12:00:30 |
医療系 |
医療介護 CBnews |
最終段階の医療、医師2割「話し合いほとんど行わず」-厚労省調査 |
https://www.cbnews.jp/news/entry/20230518210346
|
厚生労働省 |
2023-05-18 21:10:00 |
海外ニュース |
Japan Times latest articles |
Kishida and Biden hail ‘evolution’ of alliance as leaders meet in Hiroshima |
https://www.japantimes.co.jp/news/2023/05/18/national/politics-diplomacy/g7-biden-kishida-bilateral/
|
Kishida and Biden hail evolution of alliance as leaders meet in HiroshimaA senior Japanese official said the leaders held substantive talks on a range of issues from defense and economic security coordination to their response to |
2023-05-18 21:39:38 |
海外ニュース |
Japan Times latest articles |
Japan and U.K. deepen bilateral ties with new defense and tech pact |
https://www.japantimes.co.jp/news/2023/05/18/national/politics-diplomacy/japan-uk-defense-technology-agreement/
|
Japan and U K deepen bilateral ties with new defense and tech pactThe so called Hiroshima Accord will see the two sides launching new partnerships in the areas of industrial science innovation and technology and semiconductors |
2023-05-18 21:20:14 |
ニュース |
BBC News - Home |
Sats: KS2 Year 6 reading paper revealed after row over difficulty |
https://www.bbc.co.uk/news/education-65624697?at_medium=RSS&at_campaign=KARANGA
|
difficultysome |
2023-05-18 12:40:35 |
ニュース |
BBC News - Home |
BT to cut 55,000 jobs with up to a fifth replaced by AI |
https://www.bbc.co.uk/news/business-65631168?at_medium=RSS&at_campaign=KARANGA
|
giant |
2023-05-18 12:47:18 |
ニュース |
BBC News - Home |
Rishi Sunak seeks closer ties with Japan ahead of G7 summit |
https://www.bbc.co.uk/news/uk-politics-65632561?at_medium=RSS&at_campaign=KARANGA
|
defence |
2023-05-18 12:06:48 |
ニュース |
BBC News - Home |
Northern Ireland election 2023: Voters set to decide on councils |
https://www.bbc.co.uk/news/uk-northern-ireland-65622537?at_medium=RSS&at_campaign=KARANGA
|
ireland |
2023-05-18 12:32:36 |
仮想通貨 |
BITPRESS(ビットプレス) |
ビットバンク、犯罪による収益の移転防止に関する法律等の改正による変更点のお知らせ |
https://bitpress.jp/count2/3_11_13621
|
犯罪による収益の移転防止に関する法律 |
2023-05-18 21:59:21 |
コメント
コメントを投稿