Reactjs 将属性设置为不带值的html标记

Reactjs 将属性设置为不带值的html标记,reactjs,jsx,Reactjs,Jsx,我正在尝试为自定义HTML元素设置一个没有值的属性。我不想使用JavaScript函数setAttribute动态实现这一点。我特别想通过一个类变量“status”设置一个属性,不带任何值。我当前使用的属性值为“status”,我不想使用它:-> 我相信这是不可能的,但我真的很想做到这一点。所以我想听听实现这一目标的任何策略。谢谢 component.tsx class Comp extends React.Component<any, any> { status: &qu

我正在尝试为自定义HTML元素设置一个没有值的属性。我不想使用JavaScript函数
setAttribute
动态实现这一点。我特别想通过一个类变量“status”设置一个属性,不带任何值。我当前使用的属性值为“status”,我不想使用它:
->

我相信这是不可能的,但我真的很想做到这一点。所以我想听听实现这一目标的任何策略。谢谢

component.tsx

class Comp extends React.Component<any, any> {

    status: "type1" | "type2" | "type3" = "type1";

    render() {
        return(
            <container {this.status}></container>
        );
    }
}
export default Comp;

您可以生成对象(用于动态属性目的)并向其传递空字符串。DOM上的输出将是一个没有值的HTML5属性

var status = {type1: ''};

render() {
    return(
        <container {...status}></container>
    );
}
var status={type1:''};
render(){
返回(
);
}

您可以执行以下操作:

class Comp extends React.Component<any, any> {

    status: "type1" | "type2" | "type3" = "type1";


    render() {
        return(
            <container {...{[this.status]: true}}></container>
        );
    }
}
export default Comp;
class Comp.Comp组件{
状态:“类型1”|“类型2”|“类型3”=“类型1”;
render(){
返回(
);
}
}
导出默认Comp;
class Comp extends React.Component<any, any> {

    status: "type1" | "type2" | "type3" = "type1";


    render() {
        return(
            <container {...{[this.status]: true}}></container>
        );
    }
}
export default Comp;