Skip to content

Commit

Permalink
Added logic to propagate the value of each 'is_checked' field corresp…
Browse files Browse the repository at this point in the history
…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 Aug 5, 2018
1 parent 752ef57 commit b76d71b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions webpack_in/entry.jsx
Expand Up @@ -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 {
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit b76d71b

Please sign in to comment.