B
B
bagi_avt2018-07-06 21:16:17
React
bagi_avt, 2018-07-06 21:16:17

React - how to change isOpen state? Do not mutate state directly. Use setState()?

class Profile extends Component {
    state = {
        isOpen: false
    }
    

    render () {
        console.log(this.props.userss[0].name);
        (this.props.userss[0].name === "") ? console.log('не судьба') : this.state.isOpen=true;
        const body = this.state.isOpen && 
        <div> 
            <div>Name</div>
            <h3>
                {this.props.userss[0].name}
            </h3>
            <div>Number</div>
            <h3>
                {this.props.userss[0].number}
            </h3>
            <div>Login</div>
            <h3>
                {this.props.userss[0].login}
            </h3>
            <div>Karma</div>
            <h3>
                {this.props.userss[0].karma>0 ? "true" : "false"  }
            </h3>
            <div>Rating</div>
            <h3>
                {this.props.userss[0].rating}
            </h3>
         </div>;
    return (
        <div>
             {body}
        </div>
    
     )
     
}
}

export default Profile

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Shchypylov, 2018-07-06
@bagi_avt

this.setState({
 isOpen: true
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question