Permalink
Browse files

Added logic to propagate the value of each 'is_checked' field corresp…

…onding to each item in the <ListWidget> React 'state' to each <ListItem> via 'props', and to also update the checkbox within each <ListItem> accordingly.
  • Loading branch information...
maratbn committed Jul 1, 2018
1 parent 752ef57 commit b76d71b2c3c059885517608c32955be2217a7181
Showing with 5 additions and 2 deletions.
  1. +5 −2 webpack_in/entry.jsx
@@ -76,12 +76,14 @@ class TextWidget extends React.Component {
class ListItem extends React.Component {
render() {
return (<li><input type='checkbox' />{ this.props.caption }</li>);
return (<li><input type='checkbox'
checked={ this.props.isChecked }/>{ this.props.caption }</li>);
}
}
ListItem.propTypes = {
caption: PropTypes.string.isRequired
caption: PropTypes.string.isRequired,
isChecked: PropTypes.bool.isRequired
};
class ListWidget extends React.Component {
@@ -123,6 +125,7 @@ class ListWidget extends React.Component {
{ this.state.items.map((objItem, index) => (
<ListItem key={ objItem.id }
caption={ objItem.caption }
isChecked={ objItem.is_checked }
/>
)) }
</ul>

0 comments on commit b76d71b

Please sign in to comment.