Memoize React Components to Prevent Unnecessary Renders
When the state of a React component changes, the component and all of its children will re-render. While this is fine for most cases, you may have a child component [...]
When the state of a React component changes, the component and all of its children will re-render. While this is fine for most cases, you may have a child component [...]
By default, properties passed to a styled component are passed on as attributes to the native HTML element created. A regular property must be a valid HTML element attribute, or [...]
While it's easy to update an input's value using a ref, that doesn't trigger the input's onChange event, which may be an issue if you're relying on onChange to fire [...]
Sometimes you want to use useEffect() to catch a change in a state, but only after the initial value has been set. For example, you have a state called selectedId, [...]
Creating a React component that contains children can be as easy as including a children property and including {props.children} in the Return function. But knowing the proper type to use [...]
Preventing a Link or Button from moving to the next URL (or triggering a post or postback in the case of ASP.Net) is easily accomplished using the very common method [...]
It is sometimes necessary to pass a variable to a SetTimeout() callback function. By the time the callback occurs, the original variable may no longer exist, so passing a copy [...]
To check if an element has an ID: if ($(this).is('[id]') { // Has ID console.log('Has ID: ' + $(this).attr('id')); } else { // Has no ID console.log('Has no ID.'); }
Selector Starts With: $('input[name^=somePrefix]').doSomething(); Selector ENDS with: $('input[name$=someSuffix]').doSomething(); In ASP.Net: This is particularly useful in ASP.Net when you may not want to specify clientidmode static, but still want to use [...]
When a DOM object is added after the DOM has loaded, the usual process of binding an event to a specific jQuery object may not be sufficient. E.g.: Normal binding [...]