最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - onMouseover and onMouseOut Event Handle in React - Stack Overflow

programmeradmin7浏览0评论

I am beginner of React-Js and I stuck some event handling onmouserover and onmouseout.

let showUpdateRow = () => {}

let hideUpdateRow = () => {}

let bodyContent = props.linkData.map((data, index) => {
  return (
    <tr key={index} onMouseOver={showUpdateRow} onMouseOut={hideUpdateRow}>
      <td>{dataments}</td>
      <td>
        {data.link}
        <div className="updateRow" style={{ display: 'none' }}>
          <MdEdit className="editRow" />
          <MdDelete className="deleteRow" />
        </div>
      </td>
    </tr>
  )
})

onMouseOver Event, I want to show updateRow Div and OnMouseOut Event, I want to hide updateRow Div.

I need to show only updateRow div which currently mouseover inside tr. If I use ref property but on mouseover all updateRowDiv will show.

I need some help , Thanks.

I am beginner of React-Js and I stuck some event handling onmouserover and onmouseout.

let showUpdateRow = () => {}

let hideUpdateRow = () => {}

let bodyContent = props.linkData.map((data, index) => {
  return (
    <tr key={index} onMouseOver={showUpdateRow} onMouseOut={hideUpdateRow}>
      <td>{data.ments}</td>
      <td>
        {data.link}
        <div className="updateRow" style={{ display: 'none' }}>
          <MdEdit className="editRow" />
          <MdDelete className="deleteRow" />
        </div>
      </td>
    </tr>
  )
})

onMouseOver Event, I want to show updateRow Div and OnMouseOut Event, I want to hide updateRow Div.

I need to show only updateRow div which currently mouseover inside tr. If I use ref property but on mouseover all updateRowDiv will show.

I need some help , Thanks.

Share Improve this question edited Mar 4, 2019 at 15:23 hankchiutw 1,6721 gold badge14 silver badges17 bronze badges asked Mar 4, 2019 at 14:31 Kalpesh PrajapatiKalpesh Prajapati 511 gold badge1 silver badge6 bronze badges 2
  • you can track currently active row id in a private variable(say this._activeRowId) and display or hide a row inside bodyContent's loop by paring row id to this._acriveRowId – hankchiutw Commented Mar 4, 2019 at 15:19
  • is there a reason you want to do it in React? would you consider using css instead? example: codesandbox.io/s/x943nky4yq – Tubc Commented Mar 4, 2019 at 15:20
Add a ment  | 

1 Answer 1

Reset to default 2

If i understand correctly. You could declare a state for showUpdateRow and use that to show/hide your row.

So it will look something like

state = {
  showUpdateRow: false,
};

showHideUpdateRow =  (value) => {
  this.setState({showUpdateRow : value})
}

and in the bodycontent you can use

onMouseOver={showHideUpdateRow(true)} onMouseOut={showHideUpdateRow(false)}

and then in the updateRow style

style={{ display: `${this.state.showUpdateRow ? 'block' : 'none'}` }}
发布评论

评论列表(0)

  1. 暂无评论