Top React Libraries — Tooltips, Dialogs, and Cookies

Image for post
Image for post
Photo by Anh Nguyen on Unsplash

To make developing React apps easier, we can add some libraries to make our lives easier.

In this article, we’ll look at some popular libraries for React apps.

React Tooltip

React Tooltip is an easy to use tooltip library to let us add a tooltip to our app.

To install it, we run:

Then we can use it by writing:

We import the CSS so that we see some styles in our tooltips.

Then we add the Tooltip component to ley us display the tooltip.

It takes several props including some refs for the arrow and tooltip.

Also, there’s one prop to let us set the tooltip placement to be beside the trigger element which we expect.

The content of the tooltip is also in the same component.

Trigger is a component that lets us trigger the tooltip.

It’s passed in as the child of the TooltipTrigger component.

This lets us set the placement with the placement prop and the event that triggers the tooltip with the trigger prop.

We can configure how the tooltip is triggered with the components that this package comes with.

rc-dialog

rc-dialog is a React package to let us add a dialog easily in our app.

To install it, we run:

Then we can use it by writing:

We import the styles with the dialog.

Then in the App component, we have a button to open the dialog box.

When we click the button, we set the visible state to true .

Then we have the Dialog component.

We set the visible prop to the visible state.

animation has the animation we want to show when we open the dialoh.

maskAnimation is set to fade as the mask animation’s class name.

title has the dialog title.

onClose has a function that runs when we click the ‘x’ or when we click away from the dialog to close it.

The content of the dialog is between the tags.

It also supports many other options like disabling closing, enable or disable closing with the keyboard, the icon for the close button, and more.

react-cookie

react-cookie is an easy to use package for managing client-side cookies in a React app.

To use it, we install it by running:

Then we can use it by writing:

It comes with the useCookies hook which takes an array with the cookie keys we want to get.

It returns the cookies state with the cookie keys and values.

And it returns the setCookie function to let us set cookies.

It takes the key as the first argument.

The value is the second argument.

The 3rd argument has additional parameters that we can set for the cookies like the path and expiry.

There’re also functions to remove cookies, and it comes with the withCookies higher-order component to let us access cookies data and functions via props.

We can get, set, and remove cookie values.

Server-side rendering is also supported.

Image for post
Image for post
Photo by Louis Hansel @shotsoflouis on Unsplash

Conclusion

React Tooltip is an easy to use package for displaying tooltips.

rc-dialog lets us add dialog boxes in our app.

react-cookie lets us manage client-side cookies with ease.

Written by

Web developer. Subscribe to my email list now at http://jauyeung.net/subscribe/. Email me at hohanga@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store