diff --git a/src/components/trails/Trail.js b/src/components/trails/Trail.js index 1dc61bb..c116987 100644 --- a/src/components/trails/Trail.js +++ b/src/components/trails/Trail.js @@ -1,38 +1,20 @@ -import React, { Component } from "react"; +import React, { Component } from 'react' import ShowTrail from './ShowTrail' import EditTrail from './EditTrail' +import Toggle from '../../utilities/Toggle' -class Trail extends Component { +const Trail = ({ trail, update, delete: deleteAction }) => ( +
+ + {({ on, toggle }) => { + return on ? ( + + ) : ( + + ) + }} + +
+) - constructor() { - super(); - this.state = { - showComponent: false - }; - } - - onEditClick = () => { - this.setState({ - showComponent: !this.state.showComponent, - }); - } - - hideEditComponent = () => { - this.setState({ - showComponent: false - }) - } - - render() { - return ( -
- {this.state.showComponent ? - : - - } -
- ); - } -} - -export default Trail; +export default Trail diff --git a/src/utilities/Toggle.js b/src/utilities/Toggle.js new file mode 100644 index 0000000..980187d --- /dev/null +++ b/src/utilities/Toggle.js @@ -0,0 +1,16 @@ +import React, { Component } from 'react' + +export default class Toggle extends Component { + state = { + on: false + } + + toggle = () => this.setState({ on: !this.state.on }) + + render() { + const { on } = this.state + const { toggle } = this + const { children } = this.props + return children({ on, toggle }) + } +}