简体   繁体   English

ReactJs - 调用第二个函数参数

[英]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.我现在正在使用 React-Bootstrap,我想使用工具提示,但是,我不想为工具提示创建 2 个函数。 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.如果您使用的是 React 组件 (this.props) 中的 props,则不需要专门将它们与函数参数一起传递。 You could use something like this:你可以使用这样的东西:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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