In React, how can I cause anchors to do nothing on click?

前端 未结 7 1432
无人及你
无人及你 2021-01-01 15:51

I have the following html element:

 fields.push()}>Add Email

I need the href attribute so bootstra

7条回答
  •  有刺的猬
    2021-01-01 16:16

    You should call preventDefault function from onClick event like this:

    class App extends React.Component {
      onClick = (e) => {
        e.preventDefault()
        console.log('onclick..')
      }
      render() {
        return (
          Click me
        )
      }
    }
    

    You can use something like this particular to your use case:

        const renderEmails = ({ fields }) => (
          ...
           {
            e.preventDefault()
            fields.push()
          }}>Add Email
          ...
        )
    

提交回复
热议问题