how to display react variable in render function using ternary operator

前端 未结 3 1263
你的背包
你的背包 2021-01-29 07:27

why doesn\'t \'hidden\' get added to the input tag?

class FontChooser extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hidde         


        
相关标签:
3条回答
  • 2021-01-29 08:03
    <input type={this.state.hidden ? 'hidden' : 'checkbox'} id="boldCheckbox"  />
    
    0 讨论(0)
  • 2021-01-29 08:04

    You can use inline styles to hide

    <input type="checkbox" id="boldCheckbox" style={this.state.hidden ? {display: 'none'} : {} />
    

    Or you can use classes to hide

    <input type="checkbox" id="boldCheckbox" className={this.state.hidden ? classes.hidden : ''} />
    

    If you just don't want to render it

    {!this.state.hidden &&
    <input type="checkbox" id="boldCheckbox" />
    }
    
    0 讨论(0)
  • 2021-01-29 08:19
    <input type="checkbox" id="boldCheckbox" {...this.state} />
    

    or

    <input type="checkbox" id="boldCheckbox" hidden={this.state.hidden} />
    
    0 讨论(0)
提交回复
热议问题