Created
January 10, 2019 21:24
-
-
Save andrzejewsky/6938f21e8bff57c0d13d9f8a9994fe98 to your computer and use it in GitHub Desktop.
List
This file contains hidden or 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, { Component } from "react"; | |
import ListContext from "./context"; | |
import "./List.css"; | |
class List extends Component { | |
state = { | |
selectedItem: null | |
}; | |
handleSelectItem = selectedItem => { | |
this.setState({ selectedItem }); | |
this.props.onSelect(selectedItem); | |
}; | |
render() { | |
const { selectedItem } = this.state; | |
const contextValue = { | |
handleSelect: this.handleSelectItem | |
}; | |
return ( | |
<ListContext.Provider value={contextValue}> | |
<div className="list">{this.props.children({ selectedItem })}</div> | |
</ListContext.Provider> | |
); | |
} | |
} | |
export default List; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment