Want to know how to use debouncing to improve the performance of your search in React application? Check out my this article. Calling debFunction, internally, calls the onSearchText function where we're actually making an API call. Then for every key change event, we’re calling the function stored in debFunction variable after 300 milliseconds once the user has stopped typing. const debFunction = _.debounce(onSearchText, 300) In the above code, the debounce method returns a function which we’re storing in debFunction variable. Let’s build a search functionality where a user types some information as input, and we will make an APIĬall to the server to get the result based on the input. This is a very useful method that allows us to minimize the number of API calls to the server. ![]() Note: the debounce method returns a function that we invoke to make subsequent calls. Take a look at the below code: const obj1 = ]) The isEqual method performs a deep comparison between two values. ![]() Let’s explore some of the most useful methods provided by lodash. In this article we will see, some of the most useful methods provided by lodash which makes coding easy. My rule of thumb is always to start with plain vanilla JavaScript and when you have exhausted it, then bring in Lodash.According to the State of Javascript 2020 Survey results, Lodash is the second most widely used utility library in the world as it provides a lot of methods that make coding easy and fast. This means you can spend more time building your app than worrying about building the tools. There are some really useful functions that prevent you from wasting your time to re-invent the wheel. And having a good grasp of vanilla or native JavaScript is way better for your career than being proficient in using Lodash. There are so many more native functions that make programming in it so much more convenient. Such is life, am I right □ JavaScript has really evolved so much since its inception. LOL, this article was about using Lodash yet in the latter half I spend it arguing you against using it. endsWith ( 'abc', 'c' ) // ✅ Vanilla 'abc'. And au natural is always the way to go □ With modern JavaScript, you can do so much natively. With that lovely preface of asking yourself if you really need Lodash, let me further cement my case and point you to this lovely repo □ You Don't Need Lodash. My default is always to start with less and when reality tells you otherwise, then layer up □ # You don't need Lodash Of course, there are exceptions! And what those exceptions are will really depend on your situation and the person to know best is YOU! So do what works for you. If you're just having lunch with a friend, would you really bring along your suitcase? I would say a purse or small bag should be plenty. I typically use it for larger applications. I think those will result in more constructive and much more fun discussions □ # Do you really need Lodash?įor a tiny application, I wouldn't even bother with Lodash. So the next time you jump into a discussion, let we all assume positive intent, be respectful of disagreeing point of views, and deploy empathy. And we WANT people to participate, it's how we achieve better and more creative solutions. People will then tune out and not participate. And when that happens, it's not just not fun, it can be scary. However, with the absence of respect and empathy, these discussions can become toxic. As long as we approach these discussions with respect and empathy, I think it's great to have these debates. My favorite is the always on-going debate of tabs versus space □ - that's always fun to see the passion each side takes □. I think it's fantastic people when people have discussions with such passion. This will make it easier for other people in your team to quickly understand your code. ![]() I think the more important thing is consistency. But if YOU don't think the convention fits you and your team, there's nothing wrong to go against the grain. Yes, there are conventions that are agreed upon by most people. But most programming choices are subjective. ![]() I know some people can get very passionate about declaring their own stance as the rule of the law. # Improving Discussions □Īs you can see, many programming decisions are quite subjective. So I find B-1 the cleanest for me and reads better. Sure I could also go with B-3, although it's all within one import statement, I still have to deal with all those individual renaming. My personal preference is B-1 since I always like to clearly identify the Lodash functions. Import from 'lodash' const range = _range ( 1, 3 ) const random = _random ( 0, 5 ) # B-1 for the win!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |