Last active
May 8, 2020 11:01
-
-
Save MwirabuaTimothy/4e46dc2a5052e5ffb2c1e43513ddae8b to your computer and use it in GitHub Desktop.
Turning a class component to functional component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { connect } from "react-redux" | |
import { addItems } from "../../redux/actions/items" | |
const enhance = connect( | |
({ items }) => ({ items }), | |
{ addItems } | |
) | |
class ItemsList extends React.Component { | |
render() { | |
return ( | |
<div> | |
<ul> | |
{this.props.items.map((item, index) => { | |
return ( | |
<li key={index}> | |
{this.renderItem(item)} | |
</li> | |
) | |
})} | |
</ul> | |
<button onClick={this.onAddButtonClick}>Add Item</button> | |
</div> | |
) | |
} | |
renderItem = item => <div>{item}</div> | |
onAddButtonClick = e => { | |
const text = window.prompt("Enter item text:") | |
this.props.addItems(text) | |
} | |
} | |
export default enhance(ItemsList) |
abel-masila
commented
May 8, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment