AWS |
AWS News Blog |
Prime Day 2023 Powered by AWS – All the Numbers |
https://aws.amazon.com/blogs/aws/prime-day-2023-powered-by-aws-all-the-numbers/
|
Prime Day Powered by AWS All the NumbersAs part of my annual tradition to tell you about how AWS makes Prime Day possible I am happy to be able to share some chart topping metrics check out my and posts for a look back This year I bought all kinds of stuff for my hobbies including a … |
2023-08-02 14:03:16 |
AWS |
AWS Japan Blog |
プレビュー – 基盤モデルでタスクを完了させるための Agents for Amazon Bedrock |
https://aws.amazon.com/jp/blogs/news/preview-enable-foundation-models-to-complete-tasks-with-agents-for-amazon-bedrock/
|
プレビュー基盤モデルでタスクを完了させるためのAgentsforAmazonBedrockプレビューで利用可能になったAgentsforAmazonBedrockは、開発者が数回クリックするだけで基盤モデルFMを扱うフルマネージドなエージェントを作成できる新しい機能です。 |
2023-08-02 14:15:20 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
時系列データの分割 |
https://qiita.com/inoshun/items/7285e91de00586d75379
|
記事 |
2023-08-02 23:31:52 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
matplotlib.pylotでグラフを描いてみた |
https://qiita.com/neko-kamaboko/items/92a09290f8fbc51069a0
|
styleuseggplotx |
2023-08-02 23:10:10 |
AWS |
AWSタグが付けられた新着投稿 - Qiita |
AWSのEC2について |
https://qiita.com/hiro_10/items/cf0b0f4ee53872450810
|
ecelasticcomputecloud |
2023-08-03 00:00:09 |
Azure |
Azureタグが付けられた新着投稿 - Qiita |
AZ-400 に合格しました |
https://qiita.com/coitate/items/239c28af804cb5a74fd6
|
azure |
2023-08-02 23:11:23 |
Git |
Gitタグが付けられた新着投稿 - Qiita |
WSL2でSSHが使えない問題、実はネット環境に問題アリ…? |
https://qiita.com/Keichan_15/items/99cdf7e3abdbdd840cc8
|
gitclone |
2023-08-02 23:11:55 |
海外TECH |
MakeUseOf |
What Kanye West's Return to X (Twitter) Means for Free Speech |
https://www.makeuseof.com/kanye-west-twitter-x-free-speech/
|
What Kanye West x s Return to X Twitter Means for Free SpeechYe formerly known as Kanye West has been allowed back on X formerly known as Twitter Which says a lot about Elon Musk s approach to free speech |
2023-08-02 14:55:22 |
海外TECH |
MakeUseOf |
9 Things That Can Get You Banned on Snapchat |
https://www.makeuseof.com/things-can-get-you-banned-snapchat/
|
snapchat |
2023-08-02 14:45:25 |
海外TECH |
MakeUseOf |
Forgot Your Android Passcode? 5 Ways to Get Back In |
https://www.makeuseof.com/tag/forgot-android-passcode/
|
android |
2023-08-02 14:45:25 |
海外TECH |
MakeUseOf |
Why You Should Vlog With a Wide-Angle Camera Lens |
https://www.makeuseof.com/vlog-with-wide-angle-camera-lens-pros-cons/
|
selfie |
2023-08-02 14:30:23 |
海外TECH |
MakeUseOf |
How to Automatically Move Selected Files Into a New Folder on Windows 11 |
https://www.makeuseof.com/move-selected-files-new-folder-windows-11/
|
How to Automatically Move Selected Files Into a New Folder on Windows macOS users can bundle selected files into a new folder with just two clicks so why can t you Here s how to do it on Windows |
2023-08-02 14:16:24 |
海外TECH |
DEV Community |
Implementing continuous delivery pipelines with GitHub Actions |
https://dev.to/donaldsebleung/implementing-continuous-delivery-pipelines-with-github-actions-n5i
|
Implementing continuous delivery pipelines with GitHub ActionsDate The source code for this lab exercise is available on GitHub Continuous integration CI is the practice of building software from source and performing unit and integration tests in an automated fashion whenever source code changes are committed to a repository while continuous deployment CD goes a step further by automatically deploying the updated software to a development and or production environment as long as the latest software passes the entire test suite They are collectively known as CI CD both of which aim to shorten the software development lifecycle reduce the scope of manual operation and reduce the risk of human error through automation Continuous delivery on the other hand is almost identical to continuous deployment with one key difference the final step of deploying the tested software to a production environment requires manual approval While this may seem a step back from continuous deployment it solves the issue that undesired changes to a software product may not always be caught by unit and integration tests by providing a buffer for management to decide whether a particular version of the software should be released to production even if fully functional GitHub is the top software as a service SaaS platform featuring an integrated version control system VCS used by developers all around the world for hosting their software projects and code repositories large and small whether for public or private use and is home to many of the world s largest and most influential open source projects forming the backbone of the modern Internet Not surprisingly it offers first class support for fully customizable CI CD pipelines and DevOps workflows through GitHub Actions which supports both fully managed SaaS runners and self managed custom runners for varying degrees of control over the environment used to execute your automated workflows In the lab to follow we will be setting up an end to end DevOps workflow for a Flask microservice with GitHub Actions using a self managed custom runner for maximal control over the pipeline execution environment and automating deployments to a local Kubernetes cluster Furthermore we will construct separate pipelines for our development and production environments to further elaborate on the concepts of continuous deployment and delivery Continue reading on donaldsebleung com |
2023-08-02 14:33:35 |
海外TECH |
DEV Community |
Integrate security testing into your development cycle with Foundry and Diligence Fuzzing |
https://dev.to/mbogan/integrate-security-testing-into-your-development-cycle-with-foundry-and-diligence-fuzzing-ma2
|
Integrate security testing into your development cycle with Foundry and Diligence FuzzingSecurity continues to be one of the most important aspects of web As a developer you should be securing your smart contracts by ensuring that testingーspecifically a wide variety of testingーis integrated into your smart contract development lifecycle If you aren t embedding testing in your flow you re just biding your time until your smart contracts are hacked Let s look at how fuzzing meets that need and how you can quickly implement fuzzing by using the newly released Diligence Fuzzing support for your Foundry web projects Web security standards are still emergingWeb security standards are still being defined We need more tools more best practices and more I hate to say it processes Not only do we need to catch up to traditional development practices we need to surpass them After all a lot of money is at stake in our smart contracts How do we contribute to growing and maturing security in web By building better tools integrating more processes into our daily practice and automating as much as we can We have a long way to go to catch up with the automated CI CD pipelines of traditional development …but we re getting closer One step that s a good start integrating and automating fuzzing into your smart contract development cycle with Foundry and Diligenze Fuzzing Let s look at what that means and how to actually do it What is Diligence Fuzzing Fuzzing as a Service Diligence Fuzzing aka Fuzzing as a Service is a web fuzzing tool for testing smart contracts by ConsenSys Using a spec of the expected behavior of your code it creates a large number of inputs transactions that might violate this expected behavior It then runs the fuzzed inputs against your code trying to cover as much code as possible and trying to well make things fail If your code violates the specification the fuzzer raises a warning The specs are created using Scribble to annotate your smart contracts According to the Diligence site Diligence Fuzzing is “The most powerful fuzzer to find bugs and vulnerabilities before they are exploited by bad actors on mainnet What is Foundry Foundry is an open source development framework used for creating and deploying smart contracts on Ethereum EVM compatible blockchains It has lots of components a CLI a testing framework and a development framework From their own book “Foundry manages your dependencies compiles your project runs tests deploys and lets you interact with the chain from the command line and via Solidity scripts Foundry has recently become very popular I love it because it was built with security and testing in mind Interestingly Foundry ships with a fuzzing tool that works pretty well Foundry does a lot of things pretty wellーthat s another reason I love it But Diligence Fuzzing was built just for fuzzing and it takes your fuzzing game to the next level A few quick reasons It uses gray box testing as opposed to black box testing essentially allowing the fuzzer to discover and test more code paths More code coverage of course allows you to find more bugs in your code In a recent comparison it found more violations than Foundry By default it uses “stateful fuzzing where it generates sequences of transactions instead of just one transaction This can hit edge cases in the logic where multiple transactions are needed to trigger the bug It s faster And now existing Foundry projects can use Diligence Fuzzing with just a few steps How Fuzzing enhances your smart contract development cycleFuzzing is a type of software testing considered “property based testing This type of testing checks that the output of your code matches expectations for a wide variety of inputs A property based tester automatically creates a whole lot of random inputs and runs them through your code trying to find one that violates the expected output This kind of testing is usually a complement to your unit testing Your unit tests check for known flows simple inputs and edge cases you ve already caught and fixed …basically the test cases you know you need to run Fuzzing on the other hand is a software testing technique that looks for defects in your source code that you don t know about It automatically runs through a lot of possibilities more than you could ever test for manually trying to find complex and subtle bugs that you wouldn t otherwise uncover Fuzzing in actionLet s walk through the steps needed to start fuzzing a Foundry project with Diligence Fuzzing First install the Fuzzing CLI by running the following on your command line also be sure you re on Python or newer pip install diligence fuzzingYou need a Diligence fuzzing account and an API key Sign up here then go to your dashboard to create the key Now run echo FUZZ API KEY your api key here gt envThis will add your API key to a env file for the CLI Finally run the fuzzing CLI and create a new fuzzing campaign fuzz forge testThat s it You can target specific tests and contracts using the following options Usage fuzz forge test OPTIONS Command to Compile unit tests Automatically collect unit test contracts Submit to fuzzingOptions k key TEXT API key can be created on the FaaS Dashboard dry run Outputs the data to be sent to the FaaS API without making the request match contract TEXT Only run tests in contracts matching the specified regex pattern match path TEXT Only run tests in source files matching the specified glob pattern build args TEXT Additional string of forge compile command arguments for custom build strategies e g build args deny warnings build args use help Show this message and exit For more information check out the documentation here Please note a couple things Everything above assumes you have installed Foundry and written some fuzzing tests Since your existing Foundry tests probably contain several Solidity assertions and invariants the fuzzing tool can just use those to start breaking things Only some of the Foundry cheat codes are currently supported warp prank deal roll and a few more Additional support is planned soon Keep security top of mind with Fuzzing and FoundrySecuring web smart contracts is critical and it has been for a long time But with the advent of new testing tools new integrations and more rigorous processes we re getting closer to a reliable secure and mature ecosystem Fuzzing is one step towards that goal |
2023-08-02 14:22:35 |
海外TECH |
DEV Community |
Using react-intersection-observer to create a dynamic header |
https://dev.to/logrocket/using-react-intersection-observer-to-create-a-dynamic-header-3mfa
|
Using react intersection observer to create a dynamic headerWritten by Ibadehin Mojeed️The Intersection Observer API is a native API provided by modern browsers It empowers us to detect the visibility of an element relative to the viewport of the browser ーor in some cases relative to its containing element ーwith the aim of performing a certain action The react intersection observer package provides a way to implement this API in a React project In this guide we will explore how to utilize this library to monitor the visibility of different sections on a webpage and dynamically execute actions on the page header Jump ahead Overview of our demo dynamic header project Creating a dynamic header using the Intersection Observer API Implementing dynamically active menu items Creating a dynamic header using react intersection observer How to disconnect the IntersectionObserver or stop observing an elementTo follow along with this tutorial we recommend you have a basic understanding of React Now let s dive right in and get started Overview of our demo dynamic header project Consider a simple one page site that I ve put together You can find the demo and source code on CodeSandbox In the showcased demo a click on the menu item results in a seamless scroll to the corresponding page section Many single page websites with a setup similar to this demo site allow users to scroll manually through different page sections while dynamically activating the corresponding menu items In certain cases websites even alter the header s background color as the user scrolls past a specific section To accomplish all of these functionalities we can leverage the power of the Intersection Observer API The following GIF illustrates the final project We can now dive into the details Creating a dynamic header using the Intersection Observer API To better understand the react intersection observer package we will first explore how detecting element visibility worked before the Intersection Observer API then take a look at the API s underlying functionality Jump ahead within this section Detecting element visibility before the Intersection Observer API Creating an IntersectionObserver Observing multiple elements with the IntersectionObserver Applying the Intersection Observer API in React Referencing elements with the React useRef Hook Detecting element visibility prior to the Intersection Observer API Before the Observer API was introduced developers used to manage element visibility by listening for scroll events and then triggering a callback function to handle element detection as users scrolled through the page window addEventListener scroll function event Do something every time the user scrolls When using the traditional scroll event based detection method the event listener continuously fires for every scroll action and operates on the main thread As a result the system is prone to performance inefficiencies In contrast the Intersection Observer API offers a solution that asynchronously observes changes and executes code off the main thread Unlike the scroll event approach it triggers a callback only when the observed element enters or leaves the viewport The way the Intersection Observer API works makes it more performant and preferable for handling element visibility efficiently You can also read about some other use cases for this API including lazy loading of images infinite scrolling and scroll based animations Creating an IntersectionObserver To monitor the visibility of an element within a parent or ancestor element we ll follow these steps Obtain a reference to the target element Initialize a new IntersectionObserver instance by creating an observer and providing a callback function Use the observe method on the observer and pass the target element as an argumentIn its simplest form here is the code implementation of the above steps const observer new IntersectionObserver callback const targetElement document querySelector observer observe targetElement The callback function of the observer will be triggered when a specified threshold is surpassed For now you can understand this threshold to be when the target element enters or exits the visible portion of the screen Observing multiple elements with the IntersectionObserver In our project we want to monitor intersection events on multiple sections of the page instead of just one Therefore we need to make some modifications to the code mentioned above First we will obtain references to all the target sections Then we will iterate over each section and observe them individually Here is the updated code const observer new IntersectionObserver callback const targetElements document querySelectorAll targetElements forEach element gt observer observe element Applying the Intersection Observer API in React Now let s implement the intersection logic in our React project In the starter project the components Page js file is responsible for handling each section const Page gt return lt section id title gt lt section gt export default Page To monitor the visibility of the section element we will first obtain a reference to it Then we will incorporate the intersection logic within a useEffect Hook We can do all of that within the parent App component import useEffect from react function App useEffect gt const targetSections document querySelectorAll section const observer new IntersectionObserver entries gt console log entries targetSections forEach section gt observer observe section return export default App We have utilized the querySelectorAll method to obtain references to all the target lt section gt elements However in a later part of the lesson you will learn how to achieve the same using React s useRef Hook If you observe the callback function closely you will notice that it takes an entries parameter which returns an array of objects containing various details associated with each target section Based on this information we can determine whether a section is intersecting or not by checking the value of the isIntersecting property If its value is true it indicates that a threshold has been crossed for that section According to the default configuration if at least one pixel of the section is visible the threshold is considered crossed Using the target property as shown in the image above we can access the id attribute of the active section const observer new IntersectionObserver entries gt entries forEach entry gt if entry isIntersecting console log entry target getAttribute id home about project contact The id of the section will match the href attribute of the corresponding menu link Referencing elements with the React useRef Hook Instead of using methods like querySelectorAll to obtain references to all the target lt section gt elements we will utilize the useRef Hook provided by React Since we want to manage a list of refs we will implement a ref callback function This allows us to pass a function to the ref attribute which we will attach to the target element and maintain our own list To begin we will pass a callback function to the ref attribute const Page section refCallback gt return lt section id title ref refCallback gt lt section gt export default Page In the parent component we will create the callback function and ensure that we pass it down to the Page component function App const refCallback element gt if element console log element return lt gt lt main gt lt div gt sections map section index gt lt Page section refCallback key index gt lt div gt lt main gt lt gt export default App If we take a look at the console we have access to the target nodes Remember the querySelectorAll method returns a collection of elements in an array like NodeList which we then iterate over However since these entries are not in a regular array that we can directly loop over we will add them to a separate array to iterate over and manipulate them more easily To begin we will create a reference and initialize it with an empty array Then in the refCallback function we will update the array with the entries import useEffect useRef from react function App const sectionsRef useRef useEffect gt const observer new IntersectionObserver entries gt const targetSections document querySelectorAll section sectionsRef current forEach section gt observer observe section const refCallback element gt if element sectionsRef current push element return export default App To avoid recreating the refCallback function on every render we will wrap it in a useCallback Hook import useEffect useRef useCallback from react function App const refCallback useCallback element gt if element sectionsRef current push element return export default App Implementing dynamically active menu itemsNow that we can observe the sections and obtain the current section ID let s explore how we can utilize that value to dynamically add an active class to the corresponding menu item Jump ahead in this section Styling the active class for menu items Styling the header background Utilizing IntersectionObserver configuration options Styling the active class for menu items In the App component where we render the header we will create a state variable to manage the currently visible section of the page We will initialize this state variable as the home page import useState useEffect useRef from react const menus home about project contact function App const visibleSection setVisibleSection useState menus return export default App Next we will check if the state value matches the current menu item on the li If there is a match we will add an active class to that menu item menus map menu index gt lt li key index className visibleSection menu active gt lt a href menu gt menu lt a gt lt li gt We will update the state whenever the status of the isIntersecting property of a section changes to true useEffect gt const observer new IntersectionObserver entries gt entries forEach entry gt if entry isIntersecting setVisibleSection entry target getAttribute id To visualize the active menu in action we will add style rules for the active class styling active menu ul li before content width height rem background d position absolute bottom left transform scaleX transition transform s ease ul li active before transform scaleX Now as we scroll through the page sections the menu item will become active as soon as at least one pixel of the corresponding section becomes visible Styling the header background As we observed in the final demo we want the background color of the header to change from dark to white when the isIntersecting property is true for sections other than the home section To do this let s obtain a reference to the header element function App const headerRef useRef null return lt gt lt header ref headerRef gt lt header gt lt gt export default App Next within the observer we will define the logic that updates the class of the header element useEffect gt const observer new IntersectionObserver entries gt entries forEach entry gt if entry isIntersecting entry target id home headerRef current classList add bg white headerRef current classList remove bg white In the above code we checked if the intersecting section is not the home section and if it isn t we added a class to the header element The style rules for this class are declared below header background header bg white background white header bg white ul li a color black Utilizing IntersectionObserver configuration options We have the ability to control when we want the callback of the observer to be invoked by passing configuration options into the IntersectionObserver constructor useEffect gt const options root null rootMargin px threshold const observer new IntersectionObserver entries gt options In the code provided above we have applied the default values for the IntersectionObserver options Let s briefly discuss the properties The root property allows us to specify an ancestor element that serves as the viewport for checking the visibility of the target If this property is not specified or is assigned a default value of null it means we want to observe the intersection relative to the browser s viewport The rootMargin property allows us to define margins around the root element to expand or shrink it This can affect the point at which the target element is considered inside the viewport which can be useful when we need to load data before it becomes visible such as when lazy loading images or implementing infinite scrolling Specifying a positive value will expand the root element and trigger the callback even when the observed element is still away from entering the viewport Specifying a negative value will shrink the root element The threshold property allows us to specify the percentage of the elements that must be visible for it to be considered intersecting It accepts a number value between and and can also accept an array of numbers to create multiple trigger points A default value of means the element is considered intersecting as soon as a single pixel becomes visible Setting a value of means the entire element must be visibleIn our project we want to detect when visibility crosses the percent mark Therefore we will update the configuration as follows useEffect gt const options threshold See the source code and demo on CodeSandbox It may be beneficial to extract the functionality of the IntersectionObserver into a custom Hook to facilitate reusability However the react intersection observer package handles this seamlessly for us Creating a dynamic header using react intersection observer After thoroughly understanding how the native Intersection API works with React using the react intersection observer package should be straightforward and effortless Jump ahead in this section Installing the react intersection observer package Using the lt InView gt component API Avoid updating the state of other components during render Passing in react intersection observer options Using the useInView Hook Installing the react intersection observer package First we ll add the package to our project npm install react intersection observerThe react intersection observer library provides both a Hook and a component API that we can utilize to monitor the state of our target element In the next section we will begin exploring the component API Using the lt InView gt component API Similar to React s render props pattern we can pass a function to the lt InView gt component as the child prop This function will return the JSX that the IntersectionObserver will monitor Below is a basic example of how to use the lt InView gt component API import InView from react intersection observer const Component gt lt InView gt inView ref entry gt lt div ref ref gt lt p gt This paragraph is inside the viewport inView lt p gt lt div gt lt InView gt export default Component The function receives an object that contains the inView state a ref and the entry The inView state returns a Boolean value based on the visibility of the target element The function will be called with the new value whenever the state changes We can then assign the received ref to the element we want to monitor Meanwhile the entry object will provide access to all the details about the intersection state With this basic understanding let s apply the API in our React project In the src App js file of our starter project we can import the component from the react intersection observer package import InView from react intersection observer Next we need to ensure that we return the target JSX from the render props that we will pass to the lt InView gt component Since the target lt section gt element resides in a child component we will return the component itself instead Let s locate the following code lt div gt sections map section index gt lt Page section key index gt lt div gt Then update the code to the following lt div gt sections map section index gt lt InView key index gt ref inViewRef inView entry gt return lt Page section inViewRef gt lt InView gt lt div gt You may have noticed that we used an alias for the ref we passed to the child component This is necessary because we can t directly pass a named ref as props to a nested functional component unless we wrap the child component in a forwardRef or use a custom prop as we have done here Now in the child component we can assign the custom prop to the ref attribute of the target element const Page section inViewRef gt return lt section id title ref inViewRef gt lt section gt export default Page We can now define the logic that implements the dynamic header Similar to what we did in the first project we will obtain a reference to the header element and define a state for the component import useState useRef from react function App const visibleSection setVisibleSection useState menus const headerRef useRef return lt gt lt header ref headerRef gt lt nav gt lt ul gt menus map menu index gt lt li key index className visibleSection menu active gt lt a href menu gt menu lt a gt lt li gt lt ul gt lt nav gt lt header gt lt main gt lt main gt lt gt export default App After that we ll update the render props with the intersection logic lt InView key index gt ref inViewRef inView entry gt if inView setVisibleSection entry target getAttribute id entry target id home headerRef current classList add bg white headerRef current classList remove bg white return lt Page section inViewRef gt lt InView gt Don t forget to include the CSS rules styling active menu ul li before content width height rem background d position absolute bottom left transform scaleX transition transform s ease ul li active before transform scaleX header background header bg white background white header bg white ul li a color black Avoid updating the state of other components during render Though the above code works we ll see the following React warning displayed in the console Warning Cannot update a component App while rendering a different component InView This warning occurs because the component is calling the setVisibleSection updater function of the parent component while it is still rendering This creates a race condition To resolve this issue we can either place the state updater logic in a useEffect Hook or ensure that we update the state when an event occurs Fortunately the InView API provides an onChange prop option that is invoked whenever the inView state changes Inside its handler function we can access the inView status and the entry object which we can use to define the logic that implements the dynamic header The updated code now appears as follows function App const setInView inView entry gt if inView setVisibleSection entry target getAttribute id entry target id home headerRef current classList add bg white headerRef current classList remove bg white return lt gt lt main gt lt div gt sections map section index gt lt InView onChange setInView key index gt ref inViewRef gt return lt Page section inViewRef gt lt InView gt lt div gt lt main gt lt gt export default App Passing in react intersection observer options We have the ability to pass IntersectionObserver options as props to the lt InView gt component to control when the observer should be invoked Just like we did with the native API using the threshold we can update the props of the lt InView gt component to include a threshold Here is an example of how it can be done lt InView onChange setInView threshold key index gt lt InView gt See the source code and demo on CodeSandbox Using the useInView Hook Implementing the useInView Hook follows a similar approach to monitor the state of our target element This Hook accepts an optional configuration and returns the inView state the ref and the current entry Below is a basic example of how to implement the useInView Hook gt import useInView from react intersection observer const Component gt const ref inView entry useInView threshold return lt div ref ref gt lt p gt This paragraph is inside the viewport inView lt p gt lt div gt export default Component Let s apply the Hook in our React project Once again using the starter project we will apply the useInView Hook in the components Page js file ーthe same file that renders the target section element In this file let s import the useInView Hook and assign the ref to the section element that we want to monitor import useInView from react intersection observer const Page section gt const ref inView entry useInView threshold return lt section id title ref ref gt lt section gt export default Page In the same file we will add the logic that implements the dynamic header within a useEffect Hook This will result in the following code import useEffect from react const Page section gt useEffect gt if inView setVisibleSection entry target id entry target id home headerRef current classList add bg white headerRef current classList remove bg white inView entry setVisibleSection headerRef return export default Page Alternatively we can add the logic to the onChange option of the useInView Hook instead of using a separate useEffect Hook This would result in the following code const ref useInView threshold onChange inView entry gt if inView setVisibleSection entry target id entry target id home headerRef current classList add bg white headerRef current classList remove bg white Since we utilized the setVisibleSection function and headerRef variable in the logic we will pass these variables from the parent component like so import useState useRef from react function App const visibleSection setVisibleSection useState menus const headerRef useRef return lt gt lt header ref headerRef gt menus map menu index gt lt li key index className visibleSection menu active gt lt li gt sections map section index gt lt Page section setVisibleSection headerRef key index gt lt div gt lt main gt lt gt export default App Then within the child component we need to access the variables as props like this const Page section setVisibleSection headerRef gt return export default Page Finally we ll include the CSS rules for the added classes styling active menu ul li before content width height rem background d position absolute bottom left transform scaleX transition transform s ease ul li active before transform scaleX header background header bg white background white header bg white ul li a color black See the source code and demo on CodeSandbox How to disconnect the IntersectionObserver or stop observing an element With the way we re currently implementing the IntersectionObserver the target sections are being continuously monitored as they enter and exit the viewport While this behavior is suitable for our current use case there may be situations where we do not want continuous observation For example in certain scenarios we may want to stop observing an element once it becomes visible This behavior is commonly expected when lazy loading images where we want them to stay visible once they enter the viewport The unobserve methodLet s explore how we can stop observing a target element after it enters the viewport Using the native API we can call the unobserve method on the observer itself passing the target element as an argument const observer new IntersectionObserver entries observer gt entries forEach entry gt if entry isIntersecting observer unobserve entry target options It s worth noting that the IntersectionObserver constructor provides the observer instance as the second argument in the callback function The disconnect methodIt is important to disconnect the IntersectionObserver when it is no longer needed To do this we will invoke the disconnect method on the observer inside a cleanup function within the useEffect Hook useEffect gt const observer new IntersectionObserver entries gt options To disable the entire IntersectionObserver return gt observer disconnect By including the cleanup code the IntersectionObserver will be disconnected when the component unmounts preventing any potential memory leaks If you utilize the react intersection observer library the observer instances will be disconnected automatically when they are no longer needed This eliminates the need for manual disconnection making the process more efficient in your React applications The triggerOnce optionWith the react intersection observer package we can configure the observer to trigger only once after the target element enters the viewport by using the triggerOnce Boolean option Implementing the lt InView gt component will look like this lt InView triggerOnce true gt lt InView gt Meanwhile using the useInView Hook will look like so const ref inView entry useInView triggerOnce true Remember thanks to the library we re using the observer instances will automatically disconnect when they are no longer needed In this case whether we trigger the IntersectionObserver once or not it will disconnect after the component unmounts ConclusionIn this article we delved into the impressive capabilities of the react intersection observer package using it to create a dynamic header within a React project Diving into the inner workings of the native Intersection Observer API gave us a deep understanding of its functionality and versatility Another project that can be implemented using a procedure similar to the one we learned in this article is the dynamic table of contents This feature is often used in blog posts to enhance the navigation experience With the insights gained from this article developing such a project should be straightforward If you found this lesson helpful please consider sharing it with others If you have any questions or contributions feel free to share your thoughts in the comments section Get set up with LogRocket s modern React error tracking in minutes Visit to get an app ID Install LogRocket via NPM or script tag LogRocket init must be called client side not server side NPM npm i save logrocket Code import LogRocket from logrocket LogRocket init app id Script Tag Add to your HTML lt script src gt lt script gt lt script gt window LogRocket amp amp window LogRocket init app id lt script gt Optional Install plugins for deeper integrations with your stack Redux middleware ngrx middleware Vuex pluginGet started now |
2023-08-02 14:04:58 |
海外TECH |
DEV Community |
Serialization and Deserialization in JavaScript |
https://dev.to/maafaishal/serialization-and-deserialization-in-javascript-3kdd
|
Serialization and Deserialization in JavaScriptAs developers we often hear about Serialization and Deserialization but what do these terms really mean SerializationSerialization is the process of converting a data structure such as JavaScript object or array into a format that can be easily stored In JavaScript the most common serialization format is JSON JavaScript Object Notation The JSON format is easy for both human and machine to read and write Example of serialization in JavaScript using JSON const data name John age const jsonString JSON stringify data Output name John age DeserializationDeserialization is the opposite process of Serialization It converts data in its serialized format into its original data structure such as a JavaScript object or array to make the data usable and accessible in the application Example of deserialization in JavaScript using JSON const jsonString name John age const data JSON parse jsonString Output name John age Other FormatsNot only JSON there are numerous serialization formats available as listed below BSONBSON is a binary encoded data interchange format designed to be more efficient in terms of storage and transmission compared to JSON It extends JSON with additional data types and is typically used in the context of MongoDB Example of serialization amp deserialization of BSON using bson package import BSON ObjectId from bson const data id new ObjectId name John age serializationconst bytes BSON serialize data Output lt Buffer e f ca d b a a e e d a f e e gt deserializationconst doc BSON deserialize bytes Output id new ObjectId cadbaae name John age EJSONExtended JSON EJSON is a superset of JSON which means it includes all features of standard JSON and extends it additional conventions for representing certain data type and MongoDB specific constructs Example of serialization amp deserialization of EJSON using bson package import EJSON from bson const data id oid efaeb name John age serializationconst jsonString EJSON stringify data relaxed false Output id oid efaeb name John age numberInt deserializationconst data EJSON stringify data relaxed false Output id new ObjectId efaeb name John age new Int ConclusionIn summary Serialization is the process of converting data into a compact and structured format suitable for storage and transmission while Deserialization is the process of converting the serialized data back into its original format |
2023-08-02 14:03:44 |
Apple |
AppleInsider - Frontpage News |
Apple wants a Vision Pro research software engineer to build science apps |
https://appleinsider.com/articles/23/08/02/apple-wants-a-vision-pro-research-software-engineer-to-build-science-software?utm_medium=rss
|
Apple wants a Vision Pro research software engineer to build science appsAs Apple continues to crank out new developer preview builds of visionOS and readies a hardware seed program the company is also looking for a research software engineer to join its Vision Pro development team Apple Vision ProThe right candidate will have at least four years of experience with low level systems programming languages and experience with architecture debugging and optimization Apple said it s hoping to find someone with experience with research engineering tasks like rapid prototyping lab instrumentation and data collection and data visualization Read more |
2023-08-02 14:46:15 |
Apple |
AppleInsider - Frontpage News |
Apple TV+ releases trailer for new Snoopy special |
https://appleinsider.com/articles/23/08/02/apple-tv-releases-trailer-for-new-snoopy-special?utm_medium=rss
|
Apple TV releases trailer for new Snoopy specialApple TV has announced a trailer for the first ever Snoopy and Charlie Brown special to focus on the character of Marcie Source AppleMarcie has featured in a previous Charlie Brown special for Mother s Day but she s always been a supporting character Now she s the center of attention in the new Snoopy Presents One of a Kind Marcie Read more |
2023-08-02 14:32:57 |
Apple |
AppleInsider - Frontpage News |
Kuo says Apple is behind, and won't release generative AI in 2024 |
https://appleinsider.com/articles/23/08/02/kuo-says-apple-is-behind-on-ai-and-wont-release-generative-ai-in-2024?utm_medium=rss
|
Kuo says Apple is behind and won x t release generative AI in Analyst Ming Chi Kuo claims Apple can t make a ChatGPT app by but that is in conflict with other recent rumors about generative AI Steve Jobs Theater at Apple ParkMing Chi Kuo has used Apple s forthcoming earnings call to examine where he thinks the company is going over the next couple of years While he does see AI featuring in its future he disagrees with other reports claiming Apple is aiming for a app launch Read more |
2023-08-02 14:47:40 |
Apple |
AppleInsider - Frontpage News |
iPhone 15 demand will be lower than iPhone 14, says Kuo |
https://appleinsider.com/articles/23/08/02/iphone-15-demand-will-be-lower-than-iphone-14-says-kuo?utm_medium=rss
|
iPhone demand will be lower than iPhone says KuoAnalyst Ming Chi Kuo says that Apple s hardware sales for the rest of the year including the iPhone are expected to be lower than last year s figures Render of the forthcoming iPhone ProAhead of Apple s latest earnings call on August Ming Chi Kuo reports that his supply chain sources believe that shipment forecasts are almost universally weaker in H than in H Read more |
2023-08-02 14:48:06 |
海外TECH |
Engadget |
Kickstarter projects will soon have to disclose any AI use |
https://www.engadget.com/kickstarter-projects-will-soon-have-to-disclose-any-ai-use-145100394.html?src=rss
|
Kickstarter projects will soon have to disclose any AI useWith artificial intelligence becoming increasingly prominent Kickstarter wants you to know if and how it s being used in any projects on the platform The company will soon require creators to disclose any use of AI in their projects The policy will apply to every project that s submitted on or after August th “We want to make sure that any project that is funded through Kickstarter includes human creative input and properly credits and obtains permission for any artist s work that it references Kickstarter s director of trust and safety Susannah Page Katz wrote in a blog post “The policy requires creators to be transparent and specific about how they use AI in their projects because when we re all on the same page about what a project entails it builds trust and sets the project up for success The project submission process will soon include a new set of AI related questions Creators will have to disclose if their project generates outputs using AI if it primarily concerns the development of generative AI tech or if it uses AI in another way They ll need to reveal which parts of their projects feature entirely original work Kickstarter will also ask creators to state whether they have permission to use works or data that are employed in AI generated aspects of their projects They ll need to provide a sense of how their sources of data deal with consent and credit quot If the sources don t have processes or safeguards in place to manage consent such as through an opt out or opt in mechanism then Kickstarter is unlikely to allow the project quot Page Katz wrote nbsp If creators don t properly disclose their use of AI during the submission process Kickstarter may suspend the project Those who try to bypass Kickstarter s policies or purposefully misrepresent their project won t be allowed to submit another one Human moderators will review submissions and if they re accepted Kickstarter will disclose any use of AI in a new section on applicable project pages in the creator s own words The company suggests its approach will help mitigate the community s concerns over AI It formulated the policy with the help of input from its staff creators and backers as well as quot other platform leaders quot AI technologies will keep evolving quickly and as such Kickstarter plans to revisit the policy and modify it if necessary This article originally appeared on Engadget at |
2023-08-02 14:51:00 |
海外TECH |
CodeProject Latest Articles |
BookCars - Car Rental Platform with Mobile App |
https://www.codeproject.com/Articles/5346604/BookCars-Car-Rental-Platform-with-Mobile-App
|
mobile |
2023-08-02 14:13:00 |
金融 |
金融庁ホームページ |
審判期日の予定を更新しました。 |
https://www.fsa.go.jp/policy/kachoukin/06.html
|
期日 |
2023-08-02 16:00:00 |
ニュース |
BBC News - Home |
Jacob Crouch: Stepfather guilty of 'vicious' baby murder |
https://www.bbc.co.uk/news/uk-england-derbyshire-66307905?at_medium=RSS&at_campaign=KARANGA
|
fractures |
2023-08-02 14:19:54 |
ニュース |
BBC News - Home |
Harry and Meghan show united front against cyberbullying |
https://www.bbc.co.uk/news/uk-66382707?at_medium=RSS&at_campaign=KARANGA
|
people |
2023-08-02 14:37:24 |
ニュース |
BBC News - Home |
Nicholas Rossi: US fugitive who faked his death can be extradited |
https://www.bbc.co.uk/news/uk-scotland-66374767?at_medium=RSS&at_campaign=KARANGA
|
nicholas |
2023-08-02 14:29:04 |
ニュース |
BBC News - Home |
Anti-vax protester guilty of harassing Matt Hancock |
https://www.bbc.co.uk/news/uk-politics-66384100?at_medium=RSS&at_campaign=KARANGA
|
health |
2023-08-02 14:50:26 |
ニュース |
BBC News - Home |
Rhodes fires: Free holiday for evacuated tourists, Greek PM says |
https://www.bbc.co.uk/news/world-europe-66374033?at_medium=RSS&at_campaign=KARANGA
|
rhodes |
2023-08-02 14:24:22 |
ニュース |
BBC News - Home |
Housebuilder sees rise in 36-year mortgages |
https://www.bbc.co.uk/news/business-66383279?at_medium=RSS&at_campaign=KARANGA
|
affordable |
2023-08-02 14:47:00 |
ニュース |
BBC News - Home |
Women's World Cup: Jamaica savour last-16 thrill as giants Brazil fall early |
https://www.bbc.co.uk/sport/football/66380370?at_medium=RSS&at_campaign=KARANGA
|
brazil |
2023-08-02 14:24:15 |
ニュース |
BBC News - Home |
Ukraine war: Drones target Odesa grain stores near Romania border |
https://www.bbc.co.uk/news/world-europe-66379561?at_medium=RSS&at_campaign=KARANGA
|
izmail |
2023-08-02 14:41:29 |
ニュース |
BBC News - Home |
Josko Gvardiol: Manchester City agree £77m fee with RB Leipzig for defender |
https://www.bbc.co.uk/sport/football/66386222?at_medium=RSS&at_campaign=KARANGA
|
gvardiol |
2023-08-02 14:38:55 |
ニュース |
BBC News - Home |
Gianluigi Buffon: Italy legend retires aged 45 |
https://www.bbc.co.uk/sport/football/66378584?at_medium=RSS&at_campaign=KARANGA
|
football |
2023-08-02 14:36:46 |
ニュース |
BBC News - Home |
Scotland v France: Finn Russell takes on captaincy, with Jamie Ritchie absent |
https://www.bbc.co.uk/sport/rugby-union/66381103?at_medium=RSS&at_campaign=KARANGA
|
Scotland v France Finn Russell takes on captaincy with Jamie Ritchie absentFinn Russell will captain Scotland for the first time against France at Murrayfield on Saturday with Jamie Ritchie ruled out with a minor injury |
2023-08-02 14:37:51 |
ニュース |
BBC News - Home |
Women's World Cup 2023: 'England manager Sarina Wiegman could have more surprises in store' - Ellen White column |
https://www.bbc.co.uk/sport/football/66373250?at_medium=RSS&at_campaign=KARANGA
|
Women x s World Cup x England manager Sarina Wiegman could have more surprises in store x Ellen White columnEngland manager Sarina Wiegman could spring more surprises in the Fifa Women s World Cup knockout stage says Lionesses record goalscorer and BBC Sport pundit Ellen White |
2023-08-02 14:18:11 |
ニュース |
BBC News - Home |
Four takeaways from the indictment |
https://www.bbc.co.uk/news/world-us-canada-64034782?at_medium=RSS&at_campaign=KARANGA
|
broad |
2023-08-02 14:23:37 |
ニュース |
Newsweek |
プーチンはアフリカに「無償武器供与も厭わない」 ──ニジェールの隣国ブルキナファソの暫定大統領 |
https://www.newsweekjapan.jp/stories/world/2023/08/post-102338.php
|
「我々が厳しく非難しているのはただつ、ウクライナに送られたはずの武器が、実際には我々の大陸に存在し、我々の戦争を活発化させ続けていることだ。 |
2023-08-02 23:16:42 |
コメント
コメントを投稿