React change highlight (npm lib)

React Change Highlight is a react component to highlight changes in the wrapped component to enhance the UX and grap the focus of the user into the changed value of some parts like the cart in an e-commerce application for example.

You can play around with it on this sandbox 🔗

and this is a real use case we are using in our app:



you can find this module as an npm package from here 🔗 or install it directly from commands.

yarn add react-change-highlight


npm install react-change-highlight


Basically you need to wrap the components you want to highlight on change inside HighlightChange element then add ref attribute to each child in this component to be used to be highlighted.

In the following example the count variable comes from state, so when ever that function setCount() is called with any different value the background of that wrapped div will be changed

import ChangeHighlight from 'react-change-highlight';
export default () => {
  const [count, setCount] = useState(0);
  return (
      <div ref={React.createRef()}>{count}</div>

Default styling for highlighting in case the user didn’t use a custom styling using the highlightStyle property:

.react-highlight {
  background-color: #f8ffb4;
  transition: all 0.5s ease-in-out;


showAfternumber500number of milli seconds before start highlighting
hideAfternumber2500number of milli seconds before ending highlighting
containerClassNamestringclassName for component container
highlightStylestringclassName for highlighing content
disabledbooleanfalseweather you need to disable highlighting

I hope you Enjoy using it and any comments or required features are most welcomed, keep in mind that this lib still in progress. Tot ziens 👋