Why am I getting this warning `No duplicate props allowed react/jsx-no-duplicate-props`

后端 未结 4 1569
醉梦人生
醉梦人生 2021-02-04 01:00

Why am I getting this warning?

warning No duplicate props allowed react/jsx-no-duplicate-props#

It\'s showing line number 28 but t

相关标签:
4条回答
  • 2021-02-04 01:25

    It can be as simple as duplicate id on HTML:

    <input id="txt-id" id="txtID" />
    
    0 讨论(0)
  • 2021-02-04 01:28

    You probably passed the same prop twice to a Component. e.g.

    <MyComponent someProp={'a'} someProp={'b'} />
    
    0 讨论(0)
  • 2021-02-04 01:28

    I also go this error, I was rendering a component and passed 'className' twice. My solution was found here with How to apply multiple classnames to an element. I then just concated the names together, the error went away and my UI rendered perfectly.

    //Error

    <IconButton
      color="secondary"
      className={classes.button}
      className={classes.test}
      component="span"
      classes={{
        root: classes.checkRoot,
      }}
    >

    //Solution

    <IconButton
     color="secondary"
     className={[classes.button, classes.test ]}
     component="span"
     classes={{
        root: classes.checkRoot,
     }}
    >

    0 讨论(0)
  • 2021-02-04 01:29

    The warning come when any duplicate attribute is used on same tag i.e.

        <input id="a" id="b" />
        <MyComponent someProp={'a'} someProp={'b'} />
        <input placehoder="a" placeholder="a" />
        <div className='a' className='b'></div>
    
    0 讨论(0)
提交回复
热议问题