简体   繁体   中英

ReactJs - Call Second Function Parameters

I'm using React-Bootstrap now, and I want to use the tooltip, but, I don't want to create 2 functions for the tooltip. So, I'm using the second parameter for changing the text of tooltips. But, I can't call it, the function read that I'm calling the first parameter, so, how to make the function to understand that I'm using the second parameter?

//this is my custom tooltip function

function renderTooltip(props, text) {
  return (
    <Tooltip id="button-tooltip" {...props}>
      {text}
    </Tooltip>
  );
}

const Example = () => (
  <OverlayTrigger
    placement="right"
    delay={{ show: 250, hide: 400 }}
    overlay={renderTooltip('hover me 1')}
  >
    <Button variant="success">Hover me to see</Button>
  </OverlayTrigger>

 <OverlayTrigger
    placement="right"
    delay={{ show: 250, hide: 400 }}
    overlay={renderTooltip('hover me 2')}
  >
    <Button variant="success">Hover me to see</Button>
  </OverlayTrigger>
);

Thank You mastah

If you are using props from your react component (this.props), you dont need to specifically pass them with function parameters. You could use something like this:

function renderTooltip(text) {
  return (
    <Tooltip id="button-tooltip" {...props}>
      {text}
    </Tooltip>
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM