What is the proper way of converting the following codes to stateless component?
export default class About extends Component {
state = {
showKitten: false
}
handleToggleKitten = () => this.setState({ showKitten: !this.state.showKitten });
render() {
const { showKitten } = this.state;
const kitten = require('./kitten.jpg');
return (
<div className="container">
{showKitten && <div><img src={kitten} alt="kitchen" /></div>}
</div>
);
}
}
Managed to define the props, etc. The following code works on logging a message. But what would be the best way to toggle boolean?
const handleToggleKitten = () => {
console.log('Hello from here');
**// How to toggle the value of boolean here?**
};
const About = (props) => {
const { showKitten } = props;
const kitten = require('./kitten.jpg');
return (
<div className="container">
{showKitten && <div><img src={kitten} alt="kitchen" /></div>}
</div>
);
};
About.defaultProps = {
showKitten: false
};
About.propTypes = {
showKitten: PropTypes.bool.isRequired
};