Access props inside quotes in React JSX

后端 未结 9 1218
广开言路
广开言路 2020-12-04 06:11

In JSX, how do you reference a value from props from inside a quoted attribute value?

For example:



        
9条回答
  •  孤城傲影
    2020-12-04 06:43

    Note: In react you can put javascript expression inside curly bracket. We can use this property in this example.
    Note: give one look to below example:

    class LoginForm extends React.Component {
    
      constructor(props) {
        super(props);
    
        this.state = {i:1};
      }
    
      handleClick() {
        this.setState(prevState => ({i : prevState.i + 1}));
    
        console.log(this.state.j);  
      }
    
    
      render() {
    
        return (
          

    Click to change image

    ); } }

提交回复
热议问题