How to add custom html attributes in JSX

后端 未结 11 1921
南方客
南方客 2020-11-27 18:14

There are different reasons behind it, but I wonder how to simply add custom attributes to an element in JSX?

11条回答
  •  春和景丽
    2020-11-27 18:48

    You can do it in componentDidMount() lifecycle method in following way

    componentDidMount(){
        const buttonElement = document.querySelector(".rsc-submit-button");
        const inputElement = document.querySelector(".rsc-input");
        buttonElement.setAttribute('aria-hidden', 'true');
        inputElement.setAttribute('aria-label', 'input');
      }
    

提交回复
热议问题