-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project React Data & Styling #13
Labels
Comments
import React, { Component } from 'react';
class StateClass extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
classMate: ['Auzan', 'Iqbal', 'Zakin'],
classMateName: ''
};
// this.changeLoadingState = this.changeLoadingState.bind(this);
}
changeLoadingState = () => {
this.setState({
isLoading: !this.state.isLoading
});
};
getElementName = (index, data) => {
console.log(`[${index}] ${data}`);
this.setState({
classMateName: data
});
};
render() {
if (!this.state.isLoading) {
return <div onClick={this.changeLoadingState}>Ups</div>;
} else {
return (
<div id='fragment'>
<div onClick={this.changeLoadingState}>
{this.state.isLoading ? 'Ini true' : 'Ini false'}
</div>
<div>
<h1>Ini data data dari state array</h1>
<ul>
{this.state.classMate &&
this.state.classMate.map((data, index) => {
return (
<li
key={index}
onClick={() => this.getElementName(index, data)}>
{data}
</li>
);
})}
</ul>
</div>
<div>
<h1>Ini nama temen saya</h1>
{this.state.classMateName && <p>{this.state.classMateName}</p>}
</div>
</div>
);
}
}
}
export default StateClass; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sharfinaega @Taufik66645 @Zakintaliban
The text was updated successfully, but these errors were encountered: