Open In App

ReactJS ReactStrap Tooltip Component

Reactstrap is a popular front-end library that is easy to use React Bootstrap 4 components. This library contains the stateless React components for Bootstrap 4. The Tooltip component helps in displaying informative text when users hover over, focus on, or tap an element. We can use the following approach in ReactJS to use the ReactJS Reactstrap Tooltip Component.

Tooltip Props:



Creating React Application And Installing Module:

Project Structure: It will look like the following.

Project Structure

Example 1: Now write down the following code in the App.js file. Here, we have shown a tooltip at the right position without delay props.




import React from 'react'
import 'bootstrap/dist/css/bootstrap.min.css';
import { Tooltip, Button } from "reactstrap"
  
function App() {
  
    // Tooltip Open state
    const [tooltipOpen, setTooltipOpen] = React.useState(false);
  
    return (
        <div style={{
            display: 'block', width: 900, padding: 30
        }}>
            <h4>ReactJS Reactstrap Tooltip Component</h4>
            <Button id="TooltipExample">Hover me to see Tooltip</Button>
            <Tooltip
                isOpen={tooltipOpen}
                placement="right"
                target="TooltipExample"
                toggle={() => { setTooltipOpen(!tooltipOpen) }}>
                Sample Tooltip Text...
            </Tooltip>
        </div >
    );
}
  
export default App;

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Example 2: Now write down the following code in the App.js file. Here, we have shown a tooltip at the bottom position without delay props set to show tooltip after 1 second and hide it after 2 seconds.




import React from 'react'
import 'bootstrap/dist/css/bootstrap.min.css';
import { Tooltip } from "reactstrap"
  
function App() {
  
    // Tooltip Open state
    const [tooltipOpen, setTooltipOpen] = React.useState(false);
  
    return (
        <div style={{
            display: 'block', width: 900, padding: 30
        }}>
            <h4>ReactJS Reactstrap Tooltip Component</h4>
            <span id="testID">Hover Me to see Tooltip!!</span>
            <Tooltip isOpen={tooltipOpen}
                delay={{ show:1000, hide: 2000 }}
                target="testID"
                placement="bottom"
                toggle={() => setTooltipOpen(!tooltipOpen)}>
                Sample ToolTip Information...
            </Tooltip>
        </div >
    );
}
  
export default App;

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:


Article Tags :