In the realm of frontend development, the quest for enhancing user interaction remains a constant pursuit. Developers, inspired by innovation, often seek solutions to refine components for a seamless user experience. Today, we delve into the construction of an advanced dropdown component using Svelte — a framework known for its simplicity and effectiveness.
![](http://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/getpro/habr/hub/2b3/99b/964/2b399b964d456f3ad1bfddc0346b60d4.png)
JavaScript *
High-level, interpreted programming language. It is a language which is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm
All the features of modals for Vue
Vue
+ modal window
is it that simple?
In this article I will go through the most popular points that use modal windows. I’ll also tell you how to do this elegantly and highly functional. Opening multiple windows, returning a value, and integrating with vue-router
are all covered here.
React — Higher Order Components (HOC)
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/95c/319/1cc/95c3191cc9228e4a7c7f2b0a6427dd1b.png)
In the ever-evolving realm of web development, mastering advanced concepts is essential for creating robust and flexible applications. In this article, we'll delve into one of these foundational React concepts: Higher-Order Components, commonly known as HOCs.
Whether you're a seasoned developer seeking advanced techniques or a curious beginner eager to learn, we'll walk through the creation and application of HOCs step by step. Get ready to enrich your development toolkit with this powerful approach while discovering how to enhance the readability, reusability, and maintainability of your code.
React Custom Hook: useTimeout
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/a6b/efd/9b7/a6befd9b74c8afaccca422d334e58287.png)
One of the significant advantages of this custom hook is that it ensures the callback function remains up to date even if it changes during component re-renders. By using a useRef to store the callback reference, the hook guarantees that the latest version of the function is always called.
React Custom Hook: useStorage
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/4d6/077/6f2/4d60776f227acbaedaf18f313c3375ff.png)
One of the key advantages of this custom hook is its simplicity. You can use it to store any type of data, such as strings, numbers, or even complex objects, with just a few lines of code. Additionally, useStorage handles the serialization and deserialization of data for you, so you don't have to worry about converting values to and from JSON.
React Custom Hook: useStateWithValidation
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/b73/7bb/166/b737bb16619d8019db2c53f1c5c8cdbc.png)
One of the key advantages of this custom hook is its flexibility. You can pass any validation function that suits your specific requirements. Whether it's checking the length of a string, ensuring a numeric value falls within a certain range, or performing more complex validations, useStateWithValidation has got you covered.
React Custom Hook: useStateWithHistory
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/ca0/3a0/0cf/ca03a00cf44b238ce7e4ed4deefd7a4f.png)
In this article series, we embark on a journey through the realm of custom React hooks, discovering their immense potential for elevating your development projects. Our focus today is on the "useStateWithHistory" hook, one of the many carefully crafted hooks available in the collection of React custom hooks.
React + Three.js. Creating your own 3D shooter. Part 1
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/8d4/012/d81/8d4012d810fbb9450b12ff15d24ad5cd.png)
Hello, dear users of the IT world!
In the era of active development of web technologies and interactive applications, 3D-graphics is becoming more and more relevant and in demand. But how to create a 3D application without losing the advantages of web development? In this article, we will look at how to combine the power of Three.js with the flexibility of React to create your own game right in the browser.
This article will introduce you to the React Three Fiber library and teach you how to create interactive 3D games.
React Custom Hook: useScript
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/5c9/538/ba3/5c9538ba3100e4108e3470da90c59394.png)
useScript can be used in various scenarios. For instance, you can load external libraries like jQuery, enabling you to harness its powerful functionalities without adding bulk to your bundle. Additionally, you can load analytics scripts, social media widgets, or any other script necessary for your application's dynamic behavior.
React Custom Hook: useRenderCount
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/47f/695/b13/47f695b1350225f8405aa8ab08827331.png)
One of the major advantages of using useRenderCount is its simplicity. By abstracting the logic into a reusable hook, you can easily integrate it into any component without cluttering your codebase. Additionally, it provides a clear and concise way to monitor render behavior, which can be crucial for performance optimization and debugging.
React Custom Hook: usePrevious
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/042/3ac/c74/0423acc7416bfa40cee548464c45e747.png)
This custom hook can be a game-changer in various scenarios. For instance, you can utilize usePrevious to compare and visualize changes in data, track state transitions, or implement undo/redo functionality. Additionally, it can be valuable in form handling, animations, and any situation where having access to the previous value is crucial for your application's logic.
Creating a mini-game with drip effect and moving circles. Part 2. Final
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/d5d/0f0/c6b/d5d0f0c6bd8d4f3d5eac7469b66b3dab.png)
Hello, dear users of the IT world!
In modern web development there are many ways to make your website interesting and attractive to users. And even using simple techniques you can achieve great results!
I suggest you to create a mini-game from scratch yourself. And then, you can use it to liven up and add interactivity to any web page.
React Custom Hook: useOnScreen
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/252/cc4/b3a/252cc4b3af35170f5d81909a635418e1.png)
One of the key advantages of useOnScreen is its simplicity. With just a few lines of code, you can detect if an element is visible and respond accordingly. This can be immensely useful in scenarios where you want to trigger animations, lazy load images, or load additional content as the user scrolls.
Creating a mini-game with a drip effect and moving circles. Part 1
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/4a7/b18/ff1/4a7b18ff116049e45ac5f505bc82dcde.png)
Hello, dear users of the IT world!
In modern web development there are many ways to make your website interesting and attractive to users. And even using simple techniques you can achieve great results!
I suggest you to create a mini-game from scratch yourself. And then, you can use it to liven up and add interactivity to any web page.
React Custom Hook: useOnlineStatus
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/cb4/9b3/769/cb49b37690cb24dd2ec5e8187e10f54e.png)
One of the main advantages of "useOnlineStatus" is its simplicity. By importing and using this hook in your component, you can effortlessly access the online status of the user. The hook internally uses the "navigator.onLine" property to determine the initial online status and dynamically updates it whenever the user's connectivity changes.
React Custom Hook: useMediaQuery
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/e78/4ea/680/e784ea680f5df312425efa640a38ee25.png)
One of the key advantages of this custom hook is its simplicity and reusability. With just a few lines of code, you can effortlessly implement responsive behavior throughout your application. Whether you need to conditionally render components, apply specific styles, or trigger different functionality based on screen size, useMediaQuery has got you covered.
React Custom Hook: useLongPress
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/c0d/fd8/152/c0dfd8152056a89ce7cadc3b592371f7.png)
One of the key advantages of useLongPress is its simplicity. By utilizing this hook, developers can easily define a long-press action on any element in their React application. With just a few lines of code, the hook takes care of handling the intricacies of tracking the long-press duration and triggering the associated callback function.
React Custom Hook: useGeolocation
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/fb2/697/f8b/fb2697f8b19579faf3db51ed541f9063.png)
One of the key advantages of useGeolocation is its simplicity. By encapsulating the complex logic required for geolocation access and handling, this hook provides a clean and reusable solution. The hook automatically handles the loading state, updating it when geolocation data is being fetched, and sets the error state if any issues arise during the process.
React Custom Hook: useFetch
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/9ff/a09/fde/9ffa09fdeefcb5e23d30ef845f03a929.png)
One of the key advantages of useFetch is its simplicity. By abstracting away the fetch logic into a reusable hook, developers can quickly and effortlessly make HTTP requests and handle responses without repetitive boilerplate code. With just a few lines, useFetch handles the network request, parses the JSON response, and provides the resulting data.
React Custom Hook: useEventListener
![](https://webcf.waybackmachine.org/web/20231211100607im_/https://habrastorage.org/r/w1560/getpro/habr/upload_files/d99/169/046/d991690460aaadaadc3c7ff7038f5298.png)
The useEventListener hook is a versatile tool that can be used in a wide range of scenarios. Whether you need to capture keyboard events, listen for scroll events, or interact with user input, this hook has got you covered. Its simplicity and elegance make it an ideal choice for any React project, from small-scale applications to large-scale enterprise solutions.
Authors' contribution
-
alexzfort 9303.0 -
ru_vds 6221.6 -
ilusha_sergeevich 2778.0 -
azproduction 2516.8 -
alizar 2063.6 -
phillennium 1659.2 -
aio350 1619.7 -
TheShock 1133.0 -
spmbt 944.6 -
Sirion 766.0