I don't know how to write a string combination of values in the render() of React.

Asked 2 years ago, Updated 2 years ago, 63 views

render(){
    let tags = this.props.tags;
    if(!Array.isArray(this.props.tags)){
        tags = [tags];
    }
    let tagsDisplayName="name";
    if(tags.length>0){
        const category = tags[0].category;
        if(category==="product"||category==="samplecode"){
            tagsDisplayName = "name" + "description" // NG (no value displayed)
            tagsDisplayName="name"//OK (name value is displayed)
        }
    }

    return(
        <div style={this.props.style}>
            <span>{this.state.error}</span>
            <TagsInput
                Omitted.
                tagDisplayProp={tagsDisplayName}
                Omitted.

javascript reactjs

2022-09-30 21:32

1 Answers

It's hard to understand what the question is for, but
If you want to combine strings, I think you should use a template string.
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/template_strings

${tagsDisplayName} description


2022-09-30 21:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.