You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Sign inDemoInstall


Package Overview
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies



React component to highlight the changed content immediately and bring focus of the user into the changed part

Version published
Weekly downloads
increased by14.5%
Weekly downloads




All Contributors GitHub license npm version PRs Welcome

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

This is a real use case I'm using in a project UseCase

You can play around with it on this sandbox .. or clone the repo and play around with the all examples in the examples folder


yarn add react-change-highlight


npm install react-change-highlight


Basically you need to wrap the components you want to highlight on change inside ChangeHighlight element (default import) then add ref attribute to each child in this component which you want to highlight when they got their content changed.

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 as a default action, but actually it can be any kind of animation you make into the class you will pass to highlightStyle attribute.

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 is rc-highlight class and it is as follow:

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

SSR (server-side rendering)

In case of using this module in a server-side rendering app, you should make sure to create and pass your own className to the highlightStyle attribute, and to make some hint for you, add ssr attribute to the ChangeHighlight element, so it can give you a hint to add a class in your console as a warning like this.

⚠️ "react-change-highlight", As you're using server-side rendering, it's a must to create and pass your css class to the highlightStyle attribute for "ChangeHighlight" component


showAfternumber500number of milli seconds before start highlighting
hideAfternumber2500number of milli seconds before ending highlighting
modechange or newOnlychangemode of the detection, either change which is the default one to detect the changes in the parsed elements or newOnly which is useful in case of newly added element highlight (check todo example)
disabledbooleanfalsewhether you need to disable highlighting
ssrbooleanfalseyou need to pass this in case of using it with server-side rendering. (gives a hint for adding style)
highlightClassNamestringclassName for highlighing content (a must in case of SSR)
containerClassNamestringclassName for component container

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Medhat Dawoud
Medhat Dawoud

💻 📝 📖
Islam ElHakmi
Islam ElHakmi

Mohamed Gamal
Mohamed Gamal

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!



Package last updated on 29 Jan 2020

Did you know?


Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog


Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc